views:

1080

answers:

3

I was looking at Blogengine.NET today and he has an interesting setup for Themes, figured I wanted to do something similar, however.. I can't make it work at all.

For each theme he has a folder like:

/themes/Indigo/

/themes/Standard/

/themes/Mobile/

Each theme contains a site.master and they all have their own codebehind that looks like this:

public partial class site : System.Web.UI.MasterPage
{
  protected void Page_Load(object sender, EventArgs e)
  {
  }
}

Was wondering how he could have one Page_Load for each theme in 3 different places, all beeing partial classes of "site", but I gave it a shot in my VB.NET application and just as I thought it didn't work

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) 
has multiple definitions with identical signatures

I'm pretty new to this but is there a way to make this work or is it something that just works in C#?

I would like to get different masterpages and usercontrols with something like this:

MasterPageFile = "~/MasterPages/" & Theme & "/Site.master"

uc = LoadControl("~/UserControls/" & Theme & "/Box.ascx")

Or is there a better way to accomplish this?

Thanks!

A: 

You can set the MasterPage for your page during the Page_PreInit like this:

Me.MasterPageFile = "~/themes/mytheme/theme.master"

Yes I know, setting it is not the problem. I can't seem to have 3 theme.master in my web application with each having their own Page_Load() when they all are partial of the same class.Sorry if Im not making any sense, just trying to figure out how it's done in Blogengine.NET
Cyrodor
A: 

Found the solution so I'll post it here if anyone else is looking for the same thing.

Multiple identical masterpages works in a .NET Web Site but not in a .NET Web Application. Maybe someone else can explain why, I just know that's the case.

So this works in a .NET Web Site:

Me.MastePageFile = "~/themes/" & Theme & "/site.master"

But it won't work in a .NET Web Applications since there can only be one site.master.

Makes me wonder if there is another good way to stick with Web Application but still be able to do major theming like WordPress or Blogengine.NET

Cyrodor
A: 

I prefixed my template file to contain the theme name, the reason you cant have multiple of the same master file is that it will create the same class

An example of what I have achieved is as follows

ThemeName = "EA" - Provided from Web.config

Me.MasterPageFile = "~/Themes/" & ThemeName & "/" & ThemeName & "Site.Master"

Generates ~/Themes/EA/EASite.Master

I also create some generic UserControls that all my sites might use and if I want to override them with custom user controls then I check for the presence of the control in my custom user controls folder, using the same naming convention as above, and include that, if not use the custom one.

I hope this helps anyone trying to achieve the same thing I was last night. This is only first draft and may change from the production version I use but it would be a good start I think

Chris Lomax