Dave Burke : Freelance .NET Web Developer specializing in Online Communities

Supporting Multiple Master Pages in BlogEngine.NET

Supporting Multiple Master Pages in BlogEngine.NET is quite simple.  An example of a master page at dbvt.com different from my primary master page, i.e. with a different sidebar, is the Contact Page.

To get started we're going to make a couple of changes in the BE.NET source library's BlogBasePage.cs Class located in /web/controls/.  First we're going to add a property to contain our master page name.


private string dbvtMasterPage = "site.master";

public string DBVTMasterPage
{
    get { return dbvtMasterPage; }
    set { dbvtMasterPage = value; }
}


Next we'll replace the hard-coded site.Master designation with our DBVTMasterPage property OnPreInit().

 

protected override void OnPreInit(EventArgs e)
{
    if (Request.QueryString["theme"] != null)
             _Theme = Request.QueryString["theme"];

   MasterPageFile = Utils.RelativeWebRoot + "themes/" +
             _Theme + "/" + this.DBVTMasterPage;


Now in the CodeBehind.cs of our Contact Page we'll add an OnPreInit() method and specify our DBVTMasterPage property.

 

protected override void OnPreInit(EventArgs e)
{
    this.DBVTMasterPage = "contact.master";
    base.OnPreInit(e);
}


The only thing left to do is create the contact.master page!

Comments (3) | Post RSS RSS comment feed

Posted on 8/14/2008 9:43:54 PM by Dave Burke
Categories: BlogEngine.NET

Related posts

Comments

Comments are closed

Copyright © 2008 Dave Burke Consulting  |  All Rights reserved.