开发者

Is it possible to set MasterType programmatically?

开发者 https://www.devze.com 2022-12-19 19:12 出处:网络
A page could have an attribute MasterType to make Page.Master to be strong-typed: <%@ MasterType VirtualPath=\"~/Site.master\" %开发者_Go百科>

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

<%@ MasterType VirtualPath="~/Site.master" %开发者_Go百科>

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?


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; }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号