I didn't mention this explicitly in the book, as it assumes you set the Theme, not the StyleSheetTheme. There are many choices made early in the book that affect how things behave later, and it's impossible to cover / discuss all possible scenarios and variations ;)
Take a look again at this code:
Select Case Page.Theme.ToLower()
This code switches on the current Theme and shows / hide the relevant controls. When the theme has not been set explicitly, this code fails as there is no theme to switch on.
To programmatically change the styleSheetTheme you need to take a different route. Instead of handling PreInit, you need to override the StyleSheetTheme property at the page level, like this:
Public Overrides Property StyleSheetTheme() As String
Get
Return "BlueTheme"
End Get
Set(ByVal value As String)
End Set
End Property
The best location to do this is in the central BasePage class as it'll apply to all pages. Instead of returning a hard coded value of BlueTheme, you need to retrieve the selected theme from the cookie and return that.
For more information: http://msdn2.microsoft.com/en-us/library/tx35bd89(VS.80).aspx
However, I am not 100% sure that styleSheetTheme will continue to work without any side effects. Maybe it's better to stick to Theme now while you learn how it works, and then later switch to another variation?
Cheers,
Imar
---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of
Beginning ASP.NET 3.5 : in C# and VB,
ASP.NET 2.0 Instant Results and
Dreamweaver MX 2004
Want to be my colleague? Then check out this post.