Is it possible to set MasterType programmatically?
Asked Answered
C

1

6

A page could have an attribute MasterType to make Page.Master to be strong-typed:

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

If all my pages inherits specific class inherited System.Web.UI.Page itself, can I someway get access to this.Master property in it so I could call master page's methods?

Chanson answered 12/2, 2010 at 1:0 Comment(0)
M
6

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

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

or abatishchev's own variant:

public new ISiteMaster Master
{
  get { return base.Master as ISiteMaster; }
}
Malissamalissia answered 12/2, 2010 at 1:7 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.