I want to be able to set an ASP.NET Theme in a gateway page, which will determine the theme based upon a partner id or something like that. I figure I'd just stick the theme name in session and get it from there if I need it.
I'm having trouble finding the right place to put this code in a single place.
I cannot seem to see a global place you can set Theme. You have to set it for each page.
As described in MSDN you can assign the Theme property in the PreInit function for a page.
Protected void Page_PreInit(object sender, EventArgs e)
{
switch (Request.QueryString["theme"])
{
case "Blue":
Page.Theme = "BlueTheme";
break;
case "Pink":
Page.Theme = "PinkTheme";
break;
}
}
So i thought ok - i'll just do that in my master page. Unfortunately copying this exact same code into a master page doesn't work. So I thought - hmm maybe master pages dont use this event. It turns out this is true.
I REALLY dont want to have to put this theme code on every content page. That seems completely stupid. But I cannot yet find anopther way. MSDN describes only two ways to apply a theme to a page -- in the web.config or with Page.Theme.
Am i going to have to create a subclass of Page and have all my pages subclass that page, and override PreInit in that subclass? I think I must be missing something becasue I cant imagine MS really expects people to set Theme programatically on every content page.