I have a web page named MyPage.aspx and two master page named Home.master and BlanK.master. By default MyPage.aspx uses Home.master.But based on some condition I need to change the master page from Home.aspx to Blank.master.So, how to do this from code behind in c#?I mean how change the master page from code behind?
我有一个名为MyPage.aspx的网页和两个名为Home.master和BlanK.master的母版页。默认情况下MyPage.aspx使用Home.master.But基于某些条件我需要将主页面从Home.aspx更改为Blank.master.So,如何从c#后面的代码中执行此操作?我的意思是如何更改母版页从代码背后?
2 个解决方案
#1
11
Set it in the Pre_Init
event:
在Pre_Init事件中设置它:
void Page_PreInit(object sender, EventArgs e)
{
MasterPageFile = "~/Master1.master";
}
See http://odetocode.com/Articles/450.aspx for some detail and more options.
有关详细信息和更多选项,请参见http://odetocode.com/Articles/450.aspx。
#2
6
put the following line in the Page_PreInit method of your codebehind page:
将以下行放在代码隐藏页面的Page_PreInit方法中:
protected void Page_PreInit(object sender, EventArgs e)
{
this.Page.MasterPageFile = "~/Blank.master";
}
#1
11
Set it in the Pre_Init
event:
在Pre_Init事件中设置它:
void Page_PreInit(object sender, EventArgs e)
{
MasterPageFile = "~/Master1.master";
}
See http://odetocode.com/Articles/450.aspx for some detail and more options.
有关详细信息和更多选项,请参见http://odetocode.com/Articles/450.aspx。
#2
6
put the following line in the Page_PreInit method of your codebehind page:
将以下行放在代码隐藏页面的Page_PreInit方法中:
protected void Page_PreInit(object sender, EventArgs e)
{
this.Page.MasterPageFile = "~/Blank.master";
}