Can we access an enum which has been defined in the master page. I read about the master page on http://jai-on-asp.blogspot.com/2009/12/master-pages-in-aspnet-35.html
+5
A:
If you mean an actual enum
, defining it elsewhere is a better option, but the same casting below works to get at it as well.
If you want to access the property that is an enum
then cast the Master
property of your page to your master page's type. Like this:
protected void override OnLoad(EventArgs e)
{
((MyMasterPagesType)Master).MyEnumProperty = MyEnum.Value;
}
Edit:
Almost forgot, you can also have the Master
property on your page already behave as this type by using the @MasterType directive in your aspx markup.
<%@ MasterType VirtualPath="~/masters/SourcePage.master”" %>
Nick Craver
2010-01-22 12:59:38
Thanks for noting the MasterType directive. Learn something every day on here :)
Gregory
2010-01-22 13:10:52