Can the elements of the Master Page be accessed from the Content Page?
Lets say I have MasterPage1 and ContentPage1 that inherits from the MasterPage1, and the MasterPage1 has a button: Button1.
Can I change the property of that button from the content page, for example to make Button1 invisible, inactive etc? How can I accomplish this?
I am using .net2.0
master page. In the content page, you create the content by adding Content controls and mapping them to ContentPlaceHolder controls on the master page. For example, the master page might have content placeholders called Main and Footer.
To access members of a specific master page from a content page, you can create a strongly typed reference to the master page by creating a @ MasterType directive. The directive allows you to point to a specific master page. When the page creates its Master property, the property is typed to the referenced master page.
Yes...if you need to do this from the aspx page using the MasterPage it would be:
Button myButton = (Button)Master.FindControl("myButton");
myButton.Visible = false;
You have to put a reference to the MasterPage in your page/user control markup.
<%@ Reference VirtualPath="..." %>
Then in the code-behind, you just cast the Page.MasterPage to your MasterPage and access its properties.
MyMasterPage myMasterPage = (MyMasterPage)Page.Master;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With