Can I install MasterType programmatically?

A page can have a MasterType attribute to make Page.Master strong:

 <%@ MasterType VirtualPath="~/Site.master" %> 

If all my pages inherit a specific class inherited by System.Web.UI.Page itself, can I somehow access the this.Master property in it so that I can call the methods of the main page?

+6
c # master-pages
source share
1 answer

In your base class that inherits all pages, just override the Master property, something like this:

 public new SiteMaster Master { get { return base.Master as SiteMaster ; } } 

or abatischev own version:

 public new ISiteMaster Master { get { return base.Master as ISiteMaster; } } 
+6
source share

All Articles