Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting access to a custom Master page from a user control

Tags:

asp.net

We have created a Master page that inherits off the asp.net Master class. We have also got ui controls that inherit off the standard asp.net ui control class. Our Master page has a public member variable. We need to be able to access that member variable from the ui controls that we use. However we can't seem to get at it? Is it our architecture that is wrong? Or the idea itself - user control getting acces to Master page variables?

like image 922
Bernard Avatar asked May 24 '10 13:05

Bernard


People also ask

How do you access a public property defined in a master page from the content page?

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.

How do I turn off master page controls in contents?

Use enabled property and make it false so that the meaning does not get changed and the program would run as you want. i added Dim control2 As WebControl = Master. FindControl("dropdownlist2") before your line, and control2. Enabled = True and it looks fine now.


1 Answers

Generally speaking, this is probably not a great design pattern. However, you should be able to do something like this:

MyMasterType myMaster = this.Page.Master as MyMasterType;
if (myMaster != null)
{
    myMaster.PublicProperty = value;
}
like image 133
etc Avatar answered Oct 23 '22 04:10

etc