button won't redirect child Iframes with javascript

D

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>
 
A

Axel Dahmen

Put your script code to the end of the page. Then the IFrames will exist on
execution.

HTH,
Axel Dahmen
 
D

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,756
Messages
2,569,540
Members
45,025
Latest member
KetoRushACVFitness

Latest Threads

Top