Accessing page/master page methods from enclosed controls

Joined
Aug 15, 2006
Messages
2
Reaction score
0
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>
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top