This is a migrated thread and some comments may be shown as answers.

[Solved] Calling Master page menthod within iframe

1 Answer 571 Views
Ajax
This is a migrated thread and some comments may be shown as answers.
Anthony
Top achievements
Rank 1
Anthony asked on 28 May 2009, 02:45 PM
Here is my situation. I have a mater page called masterpage.master to show a total count of users. in content page, I have a iframe. Inside iframe, I have all pages to use another master page called FrameMasterPage.master.  so in one of the content page inside iframe, how can I call a method in masterpage.master.  For a content page that not inside iframe, I can use following code.

 if ((Page.Master != null) && (Page.Master is MasterPage))
            (this.Page.Master as MasterPage).UpdateUserCount(AjaxManager, ajaxcontrol);

Thanks,

1 Answer, 1 is accepted

Sort by
0
Anthony
Top achievements
Rank 1
answered on 28 May 2009, 07:48 PM
I found solution from http://forums.asp.net/t/1162285.aspx

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>

Tags
Ajax
Asked by
Anthony
Top achievements
Rank 1
Answers by
Anthony
Top achievements
Rank 1
Share this question
or