By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,836 Members | 2,059 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,836 IT Pros & Developers. It's quick & easy.

button won't redirect child Iframes with javascript

P: n/a
dh
How can a button that resides on the Main page tell the child Iframes
to redirect without the page posting back? I keep getting a javascript
error: "frames.iframe1 is null or not an object." I'm assuming this is
because when i press the button it reloads the page and the frames
can't be referenced.

here's a simple example:

<HTML>
<script language="C#" runat="server">
void Submit_Click(Object Src, EventArgs E )
{
string strjscript = "<script language='javascript'>"
+ "frames[\'iframe1\'].location='http://www.google.com';"
+ "frames[\'iframe2\'].location='http://www.yahoo.com';"
+ "</script" + ">";
Response.Write(strjscript);
}
</script>
<body>
<form runat="server">
<input type="submit" Value="Update Iframes"
OnServerClick="Submit_Click" runat="server" ID="Submit"
NAME="Submit"/>

<iframe runat="server" src="about:blank" name="iframe1" ID="iframe1"
width="300" height="500" frameborder="0" scrolling="auto"></iframe>
<br>
<iframe runat="server" src="about:blank" name="iframe2" ID="iframe2"
width="300" height="500" frameborder="0" scrolling="auto"></iframe>
</form>
</body>
</HTML>
Nov 18 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Put your script code to the end of the page. Then the IFrames will exist on
execution.

HTH,
Axel Dahmen

--------------
"dh" <cm******@yahoo.com> schrieb im Newsbeitrag
news:72**************************@posting.google.c om...
How can a button that resides on the Main page tell the child Iframes
to redirect without the page posting back? I keep getting a javascript
error: "frames.iframe1 is null or not an object." I'm assuming this is
because when i press the button it reloads the page and the frames
can't be referenced.

here's a simple example:

<HTML>
<script language="C#" runat="server">
void Submit_Click(Object Src, EventArgs E )
{
string strjscript = "<script language='javascript'>"
+ "frames[\'iframe1\'].location='http://www.google.com';"
+ "frames[\'iframe2\'].location='http://www.yahoo.com';"
+ "</script" + ">";
Response.Write(strjscript);
}
</script>
<body>
<form runat="server">
<input type="submit" Value="Update Iframes"
OnServerClick="Submit_Click" runat="server" ID="Submit"
NAME="Submit"/>

<iframe runat="server" src="about:blank" name="iframe1" ID="iframe1"
width="300" height="500" frameborder="0" scrolling="auto"></iframe>
<br>
<iframe runat="server" src="about:blank" name="iframe2" ID="iframe2"
width="300" height="500" frameborder="0" scrolling="auto"></iframe>
</form>
</body>
</HTML>

Nov 18 '05 #2

P: n/a
d h
It still didn't work. Plus, I'll be executing that script in my
codebehind file anyway. So, putting it at the end of the page can't be
an option. Thanks.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 18 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.