Preferred Language:
Listing 5.22 - DynamicMasterPage.cs
Illustrates how to create a custom base page class for an application that loads different master pages dynamically.
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);
}
}
The following web.config file sets up the custom base page class.
<?xml version="1.0"?>
<configuration>
<system.web>
<pages pageBaseType="DynamicMasterPage" />
<profile>
<properties>
<add
name="MasterPageFile"
defaultValue="Dynamic1.master" />
</properties>
</profile>
</system.web>
</configuration>
ASP.NET 3.5 Unleashed
- Containing almost 2,000 pages of code samples and in-depth explanation of the
ASP.NET 3.5 Framework, ASP.NET 3.5 Unleashed is the most comprehensive book
written on the ASP.NET 3.5 Framework.
ASP.NET 3.5 Unleashed is now available in your local bookstore and online (Published January 7, 2008).
All of the code samples from this book are hosted "live" at this website.
Click here
to view the table of contents and code samples.