Personally I use an HttpModule, for two reasons.
1. If a Theme is a global feature, applied to every page, then it should be applied at the global level, not the page level.
2. You don't have to create a base class and modify the inheritance of each page class. Especially useful when developing sites and adding new pages.
This is actually really easy to do. Here's the module I use (C#, but I have a VB version if anyone needs it):
using System;
using System.Web;
using System.Web.UI;
namespace ipona.Web.GlobalEvents
{
public class ThemeModule : IHttpModule
{
public void Init(HttpApplication context)
{
context.PreRequestHandlerExecute +=
new EventHandler(this.app_PreRequestHandlerExecute);
}
private void app_PreRequestHandlerExecute(object Sender, EventArgs E)
{
Page p = HttpContext.Current.Handler as Page;
if (p != null)
{
ProfileCommon pb = (ProfileCommon)HttpContext.Current.Profile;
p.Theme = pb.Theme;
}
}
public void Dispose()
{
}
}
}
This assumes the Theme is stored in a Profile property called Theme. Then add the module in web.config:
<httpModules>
<add name="Page" type="ipona.Web.GlobalEvents.ThemeModule" />
</httpModules>
The great thing about this is that once plugged in you don't have to do anything else.
Simon - if this is a 'bad' thing to do then do let me know.
Dave