Geeks With Blogs

Lance's TextBox

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: