Search code examples
asp.net-2.0

How do you cast from Page.Master to a specific master page in ASP.NET


I have a BasePage which inherits from System.Web.UI.Page, and every page that inherits the BasePage will have the same master page.

How do I cast the Page.Master of the BasePage to the specific master page so I can access properties on it?


Solution

  • Overriden Master can't be done (its not Virtual), and masking it with new causes an issue with the page class not being able to get its master, so the best thing to do is a second property.

    Something like:

    public CustomMasterPage MasterPage
    {
        get { return this.Master as CustomMasterPage; }
    }
    

    In your BasePage class.