15 Mayıs 2009 Cuma

Change MasterPage at runtime

Let's say that we want to change the masterpage file of a page, when the user is logged in.
You can do the following:

In the code side of the page, we can write the following code in the PreInit event, that we will define:

protected void Page_PreInit(object sender, EventArgs e) {
try
{
userID = Int32.Parse(Session["userID"].ToString());
this.MasterPageFile = "~/NewMasterPage.master";
}
catch
{
;
}
}

Hiç yorum yok: