Accessing page/master page methods from enclosed controls
I have a generic page which dynamically loads a master page as well as usercontrol(s). The masterpage may also contain one or more usercontrols.
How can the user control access methods and/or properties of the contained page/master page?
Here is the general structure of my masterpage and page. I would like both the control my_menu,ascx and my_template.ascx to be able to call/access 'PageName' property from the parent page.
*** My master Page ***
<%@ Master Language="C#" AutoEventWireup="true" %>
<%@ Register Src="my_menu.ascx" TagName="menu" TagPrefix="xx" %>
<body>
<form>
<xx:menu id="Menu" runat="server">
</xx:menu>
<asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">
</asp:ContentPlaceHolder>
</form>
</body>
*** The Page ***
<%@ Page Language="C#" %>
<script runat="server">
protected string _pageName;
public string PageName()
{ return _pageName:}
protected override void OnPreInit(EventArgs e)
{
base.MasterPageFile = Page.ResolveUrl("my.master");
ContentPlaceHolder contentPlaceHolder1 = base.Master.FindControl("ContentPlaceHolder1") as ContentPlaceHolder;
Control c = LoadControl("my_template.ascx");
contentPlaceHolder1.Controls.Add(c);
base.OnPreInit(e);
}
</script>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
</asp:Content>
I have a generic page which dynamically loads a master page as well as usercontrol(s). The masterpage may also contain one or more usercontrols.
How can the user control access methods and/or properties of the contained page/master page?
Here is the general structure of my masterpage and page. I would like both the control my_menu,ascx and my_template.ascx to be able to call/access 'PageName' property from the parent page.
*** My master Page ***
<%@ Master Language="C#" AutoEventWireup="true" %>
<%@ Register Src="my_menu.ascx" TagName="menu" TagPrefix="xx" %>
<body>
<form>
<xx:menu id="Menu" runat="server">
</xx:menu>
<asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">
</asp:ContentPlaceHolder>
</form>
</body>
*** The Page ***
<%@ Page Language="C#" %>
<script runat="server">
protected string _pageName;
public string PageName()
{ return _pageName:}
protected override void OnPreInit(EventArgs e)
{
base.MasterPageFile = Page.ResolveUrl("my.master");
ContentPlaceHolder contentPlaceHolder1 = base.Master.FindControl("ContentPlaceHolder1") as ContentPlaceHolder;
Control c = LoadControl("my_template.ascx");
contentPlaceHolder1.Controls.Add(c);
base.OnPreInit(e);
}
</script>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
</asp:Content>