button won't redirect child Iframes with javascript

  • Thread starter Thread starter dh
  • Start date Start date
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>
 
Put your script code to the end of the page. Then the IFrames will exist on
execution.

HTH,
Axel Dahmen
 
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.
 
Back
Top