如何解决如何在动态母版页中应用主题?
| 母版页中是否存在覆盖PreInit?还是可以在MasterPage中继承PreInit?解决方法
如果您所有页面都有基本页面类,则可以应用以下内容:
public partial class SiteMaster : System.Web.UI.MasterPage
{
private string _theme = \"Custom\";
public string Theme
{
get { return _theme; }
set { _theme = value; }
}
}
public class BasePage : System.Web.UI.Page
{
protected void Page_PreInit(object sender,EventArgs e)
{
var siteMaster = this.Master as SiteMaster;
if (siteMaster != null && !string.IsNullOrEmpty(siteMaster.Theme))
{
Theme = siteMaster.Theme;
}
}
}
, 您不能直接将ASP.NET主题应用于母版页。如果将主题属性添加到@ Master指令,则该页面在运行时将引发错误。
但是,在以下情况下,主题将应用于母版页:
如果在内容页面中定义了主题。母版页是在内容页的上下文中解析的,因此内容页的主题也将应用于母版页。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。