Arrao4u

…a blog by Rama Rao

Archive for the ‘MasterPages’ Category

How to load master pages dynamically

Posted by arrao4u on December 10, 2009

In Global.asax file:

void Application_PreRequestHandlerExecute(object src, EventArgs e)
{
// hook up the PreInit page handler
Page p = this.Context.Handler as Page;
if (p != null)
{
p.PreInit += new EventHandler(page_PreInit);
}
}
void page_PreInit(object sender, EventArgs e)
{
Page p = this.Context.Handler as Page;
if (p != null)
{
// set the theme and master page
// p.Theme = “MyTheme”;
p.MasterPageFile = “~/MasterPage.master”;
}
}

In the detault.aspx

It should be like this:

<%@ Page Language=”C#” AutoEventWireup=”true”  CodeFile=”Default.aspx.cs” Inherits=”_Default”%>

<asp:Content ID=”Content1″ ContentPlaceHolderID=”ContentPlaceHolder1″ Runat=”Server”>

<%–All of your code goes here–%>

</asp:Content>

Posted in ASPNET, MasterPages | Leave a Comment »