Ok I almost have it. I was overthinking this. I got rid of my theme and them manager classes and just grabbed the themes on a page load event. This works with some databound events and selected index events and changes my themes. However when I choose the theme from the dropdown and the page postback the selected item is the first item in the list and not the theme I selected. The theme of the page changes, but the dropdown just defaults back to the first item in list.
I am sure this has something to do with what I have the selected text/value equal too see code below.
The other thing I can't figure out is my session is not being saved. After I choose the theme if i click on a link to another page no theme is applied to other pages on the site.
See code below
Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
If Not Page.IsPostBack Then
'get app themes folders
Dim themes As String() = IO.Directory.GetDirectories(Request.PhysicalApplicationPath & "App_Themes")
' 'add themes to dropdown list
ddlThemes.Items.Clear()
For Each theme As String In themes
' add name not path
ddlThemes.Items.Add(theme.Substring(theme.LastIndexOf(
"\") + 1))
Next
End If
'Dropdown list events
Protected
Sub ddlThemes_DataBound(ByVal sender As Object, ByVal e As EventArgs) Handles ddlThemes.DataBound
ddlThemes.SelectedItem.Text = Page.Theme
End Sub
Protected Sub ChangeTheme_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs) Handles ddlThemes.SelectedIndexChanged
Session.Add(
"MyTheme", ddlThemes.SelectedItem.Text)
Server.Transfer(Request.FilePath)
End Sub
'BasePage Code
Public
Class BasePage
Inherits System.Web.UI.Page
Protected Overrides Sub OnPreInit(ByVal e As EventArgs)
MyBase.OnPreInit(e)
If Session("MyTheme") Is Nothing Then
Session.Add(
"MyTheme", "PSU")
Page.Theme = (
CType(Session("MyTheme"), String))
Else
Page.Theme = (
CType(Session("MyTheme"), String))
End If
End Sub
End
Class