Mega Code Archive
Loading Master Pages Dynamically for Multiple Content Pages
After registering the DynamicMasterPage class, every page in your application automatically inherits from the new base class.
Every page inherits the new OnPreInit() method and every page loads a Master Page dynamically.
File: DynamicMasterPage.cs
using System;
using System.Web.UI;
using System.Web.Profile;
public class DynamicMasterPage : Page
{
protected override void OnPreInit(EventArgs e)
{
this.MasterPageFile = (string)Context.Profile["MasterPageFile"];
base.OnPreInit(e);
}
}
After you create a new base Page class, you need to register it in the web configuration file.