gtjr92
Programmer
- May 26, 2004
- 96
I am trying to set up themes in ASP.Net 2.0 I set up an page load event that grabs the themes by checking the app_themes folder. Added some events for my dropdown list. There are 2 issues i am having
1. When i choose a theme from my dropdown it 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.
2. 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
1. When i choose a theme from my dropdown it 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.
2. 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
Code:
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
Code:
'dropdown 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
Code:
'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