Changing ASPX’s MasterPage at Run-time

02 Jan

In this post we will learn how to change the MasterPage for any page.aspx … Really, sometimes we have to change the MasterPage at the run-time of the application.

First you have to know that the event we will write the code under it is “Page_PreInit” … as following:

protected void Page_PreInit(object sender, EventArgs e)
//check the user weather user is logged in or not
if (Session[“LoggedIn”] == null)
this.Page.MasterPageFile = “~/User.master”;
this.Page.MasterPageFile = “~/Admin.master”;

Leave a comment

Posted by on January 2, 2012 in ASP .NET


Tags: , , , , , ,

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: