Passing events between frames

Last post 09-26-2007 7:23 AM by Aeson07. 5 replies.

Sort Posts:

  • Passing events between frames

    09-24-2007, 3:52 PM
    • Participant
      843 point Participant
    • Aeson07
    • Member since 09-14-2007, 2:11 PM
    • VA, USA
    • Posts 230

    I'm new to AJAX so I'm sorry if this is a stupid question.

    I have 2 pages in a frameset and I need to update the content of one frame based on a button click from another frame.  How would I get this to work using AJAX?  Would I need to have some sort of central update panel?

     

  • Re: Passing events between frames

    09-24-2007, 8:02 PM
    • Star
      13,605 point Star
    • gt1329a
    • Member since 06-24-2002, 12:53 AM
    • Atlanta
    • Posts 2,248
    • ASPInsiders
      TrustedFriends-MVPs

    You can use __doPostBack() to trigger events in one frame from the other.  Say you wanted to trigger an UpdatePanel, upContent in a frame named "content", you could do it with:  parent.content.__doPostBack('upContent', '');

    Encosia - ASP.NET, jQuery, AJAX, and more.

    Latest article: Emulate ASP.NET validation groups with jQuery validation
  • Re: Passing events between frames

    09-25-2007, 6:26 AM
    Answer

    Hi,

    See Page Access within IFrame using Ajax.

    When the user clicks on a button on Page B, You need to force an 'update panel' on Page A to do a postback (so it can refresh). 

    You can hide a button in page A, and set it to be a trigger of the updatepanel, then you can access to the button by using "window.parent.document.getElementById('Button1')" in page B.

    Try the following codes,it works great:

    Page A

    <%@ Page Language="C#" %>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    <script runat="server">

        protected void Button1_Click(object sender, EventArgs e)
        {
            Label1.Text = DateTime.Now.ToString();
        }
    </script>

    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title>Untitled Page</title>
    </head>
    <body>
        <form id="form1" runat="server">
            <div>
                <asp:ScriptManager ID="ScriptManager1" runat="server">
                </asp:ScriptManager>
                <asp:UpdatePanel ID="UpdatePanel1" runat="server">
                    <ContentTemplate>
                        <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
                            <div style="visibility:hidden"><asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" UseSubmitBehavior="false" /></div>
                    </ContentTemplate>
                </asp:UpdatePanel>
                <iframe src="Default13.aspx" mce_src="Default13.aspx"></iframe>
            </div>
        </form>
    </body>
    </html>

    Page B

    <%@ Page Language="C#" %>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    <script runat="server">

    </script>

    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
        <title>Untitled Page</title>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
            <input type="button" onclick="javascript:window.parent.document.getElementById('Button1').click();" name="Button1" value="Button" id="Button1" /></div>
        </form>
    </body>
    </html>

    Let me know if you need more info.

    If this help you,don't forget mark it as a answer.Thanks!

    Best Regards,

    Sincerely,
    Jin-Yu Yin
    Microsoft Online Community Support
  • Re: Passing events between frames

    09-25-2007, 10:40 AM
    • Participant
      843 point Participant
    • Aeson07
    • Member since 09-14-2007, 2:11 PM
    • VA, USA
    • Posts 230

    Thanks for the response.

    I understand how this should work if I was using an iFrame, but since I'm using a frameset the only thing that returns with a window.parent.document call is my other frame (going with this example, window.parent.document.getElementByID can find Page A's frame, but not an element within page A itself).  I've tried working my way down to find the button within page A's updatepanel but with no luck so far.  Is there a way to go from Page B to a frameset index page to Page A's updatepanel?  Any help is appreciated.

  • Re: Passing events between frames

    09-26-2007, 3:20 AM
    Answer

    Hi,

    It is the same!

    Like this:

     Index.html:

    <html>
    <frameset cols="25%,75%">
    <frame src="Default14.aspx"></frame>
    <frame src="Default15.aspx"></frame>
    </frameset>
    </html>

    Default14.aspx

    <%@ Page Language="C#" %>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    <script runat="server">

        protected void Button1_Click(object sender, EventArgs e)
        {
            Label1.Text = DateTime.Now.ToString();
        }
    </script>

    <html xmlns="http://www.w3.org/1999/xhtml">
    <head id="Head1" runat="server">
        <title>Untitled Page</title>
    </head>
    <body>
        <form id="form1" runat="server">
            <div>
                <asp:ScriptManager ID="ScriptManager1" runat="server">
                </asp:ScriptManager>
                <asp:UpdatePanel ID="UpdatePanel1" runat="server">
                    <ContentTemplate>
                        <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
                            <div style="visibility:hidden"><asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" UseSubmitBehavior="false" /></div>
                    </ContentTemplate>
                </asp:UpdatePanel>
            </div>
        </form>
    </body>
    </html>

    Default15.aspx

    <%@ Page Language="C#" %>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    <script runat="server">

    </script>

    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head id="Head1" runat="server">
        <title>Untitled Page</title>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
            <input type="button" onclick="javascript:window.parent.document.frames[0].document.getElementById('Button1').click();" name="Button1" value="Button" id="Button1" /></div>
        </form>
    </body>
    </html>

    Best Regards,

    Sincerely,
    Jin-Yu Yin
    Microsoft Online Community Support
  • Re: Passing events between frames

    09-26-2007, 7:23 AM
    • Participant
      843 point Participant
    • Aeson07
    • Member since 09-14-2007, 2:11 PM
    • VA, USA
    • Posts 230

    Oh ok, I see now.  I got it working, thank you for all of your help Big Smile.

Page 1 of 1 (6 items)