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?
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.
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.
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;
}
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