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”;