Windows VistaWindows 2003Visual Studio 2005Windows 2000Windows XP.NET 2.0C# 2.0中级开发Visual StudioWindows.NETASP.NETC#
运行时更改主页
通过用户代码在运行时更改母版页。
引言
Some times we have to change MasterPage of a Page at runtime by user code below is the trick for changing master page at runtimeThere is a Event <CODE>Page_PreInit who will be executing just before the page render. We have to do code in this event like below
protected void Page_PreInit(object sender, EventArgs e)
{
if (Membership.GetUser() == null) //check the user weather user is logged in or not
this.Page.MasterPageFile = "~/General.master";
else
this.Page.MasterPageFile = "~/myMaster.master";
}
we can change the content of master page from inherited page too like below <CODE>Master.FindControl("nameLbl").Visible = true;