posts - 598 , comments - 849 , trackbacks - 247

My Links

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

Tag Cloud

Archives

Post Categories

Blogs

Miscellanous

Noteworthy Stuff

Popular Posts

Setting a Master Page Dynamically

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:

Print | posted on Tuesday, August 17, 2010 3:04 PM | Filed Under [ Programming ]

Feedback

No comments posted yet.
Post A Comment
Title:
Name:
Email:
Comment:
Verification:
 

Powered by: