button won't redirect child Iframes with javascript

Discussion in 'ASP .Net' started by dh, Aug 20, 2004.

  1. dh

    dh Guest

    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>
    dh, Aug 20, 2004
    #1
    1. Advertising

  2. dh

    Axel Dahmen Guest

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

    HTH,
    Axel Dahmen



    --------------
    "dh" <> schrieb im Newsbeitrag
    news:...
    > 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>
    Axel Dahmen, Aug 22, 2004
    #2
    1. Advertising

  3. dh

    d h Guest

    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!
    d h, Aug 22, 2004
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Chad
    Replies:
    4
    Views:
    8,312
  2. Jeff Rodriguez
    Replies:
    23
    Views:
    1,086
    David Schwartz
    Dec 9, 2003
  3. Sal
    Replies:
    1
    Views:
    380
  4. Oscar

    Iframes, child and parent

    Oscar, Apr 21, 2005, in forum: Javascript
    Replies:
    1
    Views:
    122
  5. Jason Carlton
    Replies:
    4
    Views:
    157
    Thomas 'PointedEars' Lahn
    Dec 16, 2009
Loading...

Share This Page