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
Tags: No tags for this post

Related posts

Comments

8/15/2008 5:40:06 AM Permalink

Interesting.  I just saw the post on the this on the BE forums yesterday and I guess I should have read it all better.  I couldn't figure out what the point was.  Now I see what you are doing with the contact page.  

When I do these types of things, I always try to stay within the existing BE structure and not make changes to the code base if I can help it.  My solution has always been to just make the site.master page more dynamic.  I'll have it check what page it is actually displaying in the page_load and then show whatever needs to be showed for the special page or pages.

I'm not sure if that is as clean or not, but it allows me to upgrade my site without having to worry about merging in my personal changes which would take sometime.

Al Nyveldt United States |

8/15/2008 5:53:32 AM Permalink

Al, You're right, of course, staying away from the BE.Core.  If I updated the .Core libraries as often as you I'd definitely employ a different solution.  Thanks much for the comment!

Dave Burke United States |

11/7/2008 7:40:39 AM Permalink

Trackback from Web Development Community

Dave Burke - Supporting Multiple Master Pages in BlogEngine.NET

Web Development Community |

Comments are closed

This site was built with the Sueetie .NET Open Source Community Framework. Learn more about Sueetie at Sueetie.com.