[英]Is it possible to call a web form in multiple master pages?
我有一个Web表单,我希望它可以访问masterpage1和masterpage2。 可能吗? 如果有,怎么样?
提前致谢。
为简化起见,假设您已在Session
存储状态,该Session
选择主页面代码隐藏。 在此示例中,您可以拥有2个母版页,并且同时只使用其中一个母版页:
//PreInit event of your desired page
protected override void OnPreInit(EventArgs e)
{
if (!string.IsNullOrEmpty(Page.MasterPageFile))
{
if (Session["MyStatus"] == "1")
{
Page.MasterPageFile = "~/MyMaster1.master";
}
else
{
Page.MasterPageFile = "~/MyMaster2.master";
}
}
}
如果要动态嵌套两个主页,可以这样做。 在这里你有2个主页同时:
protected override void OnPreInit(EventArgs e)
{
if (!string.IsNullOrEmpty(Page.MasterPageFile))
{
if (Session["NestMaster"] == "1")
{
//setting a MasterPage to the Masterpage of the current page
Page.Master.MasterPageFile = "~/MasterMaster.master";
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.