Geeks With Blogs

News

qrcode

Lance Robinson

Create Your Badge

Lance Robinson is a software engineer in Durham, Chapel Hill, Raleigh, and surrounding areas. More about Lance.

 Subscribe


Lance's TextBox » About Me » My Resume »Twitter

To set an ASPNET master page dynamically, use the Page_PreInit function and set the Page.MasterPageFile property.  For example:

protected void Page_PreInit(object sender, EventArgs e)
{
  this.Page.MasterPageFile = "~/MasterPages/" + mymaster + ".Master";
}

In the above example, mymaster should be set by whatever your requirements dictate – read from DB/CMS/whatever.  The page (aspx) itself shouldn’t have any other reference to the master page (ie, no “MasterPageFile attribute in the page directive), however it will still need the content placeholders, of course.

Technorati Tags:
Posted on Tuesday, August 17, 2010 3:04 PM Programming | Back to top


Comments on this post: Setting a Master Page Dynamically

No comments posted yet.
Your comment:
 (will show your gravatar)


Copyright © Lance Robinson | Powered by: GeeksWithBlogs.net | Join free