Getting access to a custom Master page from a user control
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 w开发者_如何学Pythone 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?
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;
}
Here you go: http://msdn.microsoft.com/en-us/library/xxwa0ff0.aspx
from: Accessing masterpage properties from child pages in ASP.net VB
精彩评论