Page Access within IFrame using Ajax.

Last post 07-15-2009 11:00 PM by Jmaur. 6 replies.

Sort Posts:

  • Page Access within IFrame using Ajax.

    06-03-2007, 6:22 AM
    • Member
      point Member
    • TwoSeven
    • Member since 06-03-2007, 10:08 AM
    • Posts 4

    I have the following scenario.

    Page A {

         IFrame {

             Page B 

         }

    }

    When the user clicks on a button on Page B, I need to force an 'update panel' on Page A to do a postback (so it can refresh).  However, there seems to be no way to get access to Page A from Page B.  The 'parent' property is null, and so is 'previous_page' which I think is a bug because I would have thought that since the IFRAME loaded PageB, at least PageBs 'parent' property would have been set to the iframe.

     I have tried using cross page posting to get previous_page to work. However, if one sets up cross page posting, the _target property of page B no longer points to the Iframe and the page loads in a new window (kind of defeating the purpose of ajax really).

     The only solution I can think of is to force the browser to reload page A (or even the whole site)- but how does one do this from within page B ?

     
    If possible, I need to put the solution code inside the 'button_click' function in the code behind page for page B. 

     

     TwoSeven.
     



     


     


     

    Filed under: , ,
  • Re: Page Access within IFrame using Ajax.

    06-04-2007, 3:34 AM
    • Contributor
      2,560 point Contributor
    • Sohnee
    • Member since 02-02-2007, 10:18 PM
    • UK
    • Posts 492

    It's worth noting that iframe's have not been included in the XHTML 1.1 definition.

    If you're using .NET - why not use a control rather than an iframe / or use a proper bit of AJAX, which doesn't rely on inframes.

  • Re: Page Access within IFrame using Ajax.

    06-04-2007, 5:19 AM
    • Member
      point Member
    • TwoSeven
    • Member since 06-03-2007, 10:08 AM
    • Posts 4

    Hi,

    I am using XHTML Transitional which still supports IFRAME.  Will move to XHMTL Strict (I believe Object tag) when MS support it in their end products :)

    However, this is not related to the problem, which is - how does one get a handle to the parent page?

     

    Also, I am not aware of any controls that support the same functionality as the IFrame without a considerable amount of development. But I am happy to be pointed in the direction of some.  It just needs to support the loading of dynamic web pages of variable length.
     

     


     

  • Re: Page Access within IFrame using Ajax.

    06-05-2007, 12:11 AM
    Answer

    Hi,TwoSeven

    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!

    Sincerely,
    Jin-Yu Yin
    Microsoft Online Community Support
  • Re: Page Access within IFrame using Ajax.

    06-05-2007, 5:57 AM
    • Member
      point Member
    • TwoSeven
    • Member since 06-03-2007, 10:08 AM
    • Posts 4

    Hey, thanks for that, its looking like its the solution - I was trying something similar earlier but I didnt use the <input> part.  I shall investigate this as a workaround solution.

    My next quest is to try and get that little bit of javascript (or a similar bit of code) to work in the OnLoggedIn method for an <asp:Login> control. The login control is the button that they press (login) and the logged in status on the parent page is what I want to change.  In preference I would like to put my code in the OnLoggedIn method in the code behind (although I didnt say this in my previous post). 

    If its not possible, I shall close this off as I have enough info to write that component in pure javascript and dispense with asp.net. Hopefully MS will populate the parent property in the next release of the product. It is after all, a standard 'container' design pattern - even basic Win32 programming supplies a 'parent' property windows and controls.

    Regards.

     TwoSeven



     

     


  • Re: Page Access within IFrame using Ajax.

    02-22-2008, 5:44 AM
    • Member
      2 point Member
    • Hassanur
    • Member since 02-22-2008, 10:37 AM
    • Posts 1

    It was nice, but unfortunately not working with me.


    I have the same problem. I need to access  a page's (page A) control to hide when any button is clicked on iframe (which is using another page, page B). I used your code, but "window.parent.document.getElementById('Button1').click();" could not find the button, and javascript exception is raised.

     Thanks,

  • Re: Page Access within IFrame using Ajax.

    07-15-2009, 11:00 PM
    • Member
      2 point Member
    • Jmaur
    • Member since 07-15-2009, 10:52 PM
    • Posts 1

    When this happens, try getting the button id from the html code of the page that contains the button (ie. from the mentioned example, open Page A in a browser that contains Button1, right click on the page and select  View Source then locate the button id), the id might be something like ct100_Button1, then use this id value instead.

Page 1 of 1 (7 items)