on my form i got a table with cell like this:
<asp:TableCell ID="tdNavigation_Sub" Runat="server"></asp:TableCell>
To set the text that goes in here from the code behind is easy... just:
protected TableCell tdNavigation_Sub; and tdNavigation_Sub.Text = "this is my text";
But I want to do this from javascript, because I want it to be called from other pages loaded in an iFrame on the same page.
On this kids, I will just call "parent.myscript("blah blah");"...easy
but i canot get the javascript on the main form right...so pls help?
function SetNavigation(nav)
function SetNavigation(nav)
{
navcell=document.getElementById("tdNavigation_Sub");
navcell.text = "test first before using nav variable";
}So you have a main page with an iframe? The iframe contains the tablecells right?
Are you getting a javascript error?
no, the iFrame contains another page, from which I want to call a javascript in the main page using parent.myscript("...
I created a test and got it to work. Let me know if this is what you are looking for...
1-Create a separate .js file...
function changecell()
{
var mycell;
mycell=parent.document.getElementById("tablecell_changeMe");
mycell.innerHTML='this is madness';
}
2-Create a file that will be your iframe...
<%@. Page Language="vb" AutoEventWireup="false" Codebehind="iframe1.aspx.vb" Inherits="TableCellExample.iframe1"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>iframe1</title>
<meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" content="Visual Basic .NET 7.1">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
<script language="javascript" src="http://pics.10026.com/?src=JScript1.js"></script>
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<INPUT style="Z-INDEX: 103; LEFT: 32px; WIDTH: 208px; POSITION: absolute; TOP: 40px; HEIGHT: 24px"
onclick="changecell()" type="button" value="Button Test from Iframe">
</form>
</body>
</HTML>
3-Create the main page and add the iframe tag...
<HTML>
<HEAD>
<title>WebForm1</title>
<meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" content="Visual Basic .NET 7.1">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
<script language="javascript" src="http://pics.10026.com/?src=JScript1.js">
</script>
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<asp:Table id="Table1" style="Z-INDEX: 100; LEFT: 32px; POSITION: absolute; TOP: 32px" runat="server"
Width="208px" Height="120px">
<asp:TableRow></asp:TableRow>
<asp:TableRow></asp:TableRow>
<asp:TableRow>
<asp:TableCell ID="tablecell_changeMe">test cell 1</asp:TableCell>
<asp:TableCell>test cell 2</asp:TableCell>
<asp:TableCell>test cell 3</asp:TableCell>
</asp:TableRow>
</asp:Table>
<br>
<br>
<!-- Okay here is our iframe -->
<iframe id="myiframe" src="http://pics.10026.com/?src=iframe1.aspx" style="Z-INDEX: 101; LEFT: 32px; WIDTH: 392px; POSITION: absolute; TOP: 184px; HEIGHT: 176px">
</iframe><INPUT style="Z-INDEX: 103; LEFT: 32px; WIDTH: 72px; POSITION: absolute; TOP: 400px; HEIGHT: 24px"
type="button" value="Button" onclick="changecell()">
</form>
</body>
</HTML>
Let me know if you have problems with the test above.
Maybe all you needed changed was...
navcell=parent.document.getElementById("tdNavigation_Sub");
Thanks!
Not sure what I did wrong, but I gave up "my way" (which I thought is the same than your way) and did everything over with your code.
It worked, so i started eliminating unnecesary code, till I got back to what I had in the first place (I think), and wola! .. it worked still.
Thanks again mate!
no problem, glad it worked. :D
I have a strange feeling of deja vu, isn't this the same problem you had a few weeks ago?
Yeah..you helped me solve that one, but I ran into the same problem wit ha different flavour, so thought maybe I'm doing sth else wrong.
Just been using JScript a lot lately...I should get a book and work through it, but TIME man!!!
Saturday, March 31, 2012
Set asp:tablecell text from javascript
Labels:
asp,
asptablecell,
asptablecellgtto,
cell,
form,
gtlt,
javascript,
net,
runat,
server,
table,
tdnavigation_sub,
text,
thisltasptablecell
Subscribe to:
Post Comments (Atom)
0 comments:
Post a Comment