I believe that I have successfully implemented theming with the following code:
In Web.Config:
<profile>
<properties>
<add name="PreferredTheme" type="string" defaultValue="Blue"/>
</properties>
</profile>
Create a new file: /App_Code/BasePage.
vb
Imports System.Web.UI.Page
Public Class BasePage
Inherits System.Web.UI.Page
Protected Overrides Sub OnPreInit(ByVal e As System.EventArgs)
MyBase.OnPreInit(e)
Dim MyProfile As System.Web.Profile.ProfileBase
MyProfile = HttpContext.Current.Profile
Me.Theme = MyProfile.GetPropertyValue("PreferredTheme")
End Sub
End Class
In MasterPage.master I created several imagebuttons representing different theme colors.
In MasterPage.master.
vb:
Sub ImageButton_Command(ByVal sender As Object, ByVal e As CommandEventArgs)
If (e.CommandName = "setTheme") Then
Profile.SetPropertyValue("PreferredTheme", e.CommandArgument)
Response.Redirect(Request.Path)
End If
End Sub
Change the Inherits directive of all pages that you want to access these imagebuttons to
Inherits BasePage
The problem I am still having is that the pages are cached. If you visit a page with one theme and then change the theme and then revisit a page, that revisited page may be cached and will show up using the previous theme. I know that I can add the directive:
<%@ OutputCache Location="None" %>
to make sure that the page is not cached.
Is there a better solution? Most users don't switch themes that often.