gtjr92 Posted April 11, 2006 Posted April 11, 2006 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, view state is enabled for my dropdown list -ddlthemes 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 End Sub '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 class inherited into above page. Imports Microsoft.VisualBasic Imports System Imports System.Data Imports System.Configuration Imports System.Web Imports System.Web.Security Imports System.Web.UI Imports System.Web.UI.WebControls Imports System.Web.UI.WebControls.WebParts Imports System.Web.UI.HtmlControls 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", "Black") Page.Theme = (CType(Session("MyTheme"), String)) Else Page.Theme = (CType(Session("MyTheme"), String)) End If End Sub End Class Quote
Administrators PlausiblyDamp Posted April 11, 2006 Administrators Posted April 11, 2006 Have you tried it without the ddlThemes_DataBound event handler - that shouldn't be required to maintain the correct selected item. Also is there a reason why you are doing a Server.Transfer(Request.FilePath) in the ChangeTheme_SelectedIndexChanged - again this shouldn't be required. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
gtjr92 Posted April 12, 2006 Author Posted April 12, 2006 re Have you tried it without the ddlThemes_DataBound event handler - that shouldn't be required to maintain the correct selected item. Also is there a reason why you are doing a Server.Transfer(Request.FilePath) in the ChangeTheme_SelectedIndexChanged - again this shouldn't be required. I tried removing the Server.Transfer(Request.FilePath) that does make a change, but not the one i desire. With this change when i click on the drop down list it changes to the wrong theme. IE if i click on a "green" them it changes to the red theme, etc I will try taking out the drop down events you suggested in the morning thanks Quote
gtjr92 Posted April 12, 2006 Author Posted April 12, 2006 Re Have you tried it without the ddlThemes_DataBound event handler - that shouldn't be required to maintain the correct selected item. Ok commented this out and it still works the same so i guess it is not neccessary. Also is there a reason why you are doing a Server.Transfer(Request.FilePath) in the ChangeTheme_SelectedIndexChanged - again this shouldn't be required when i comment out the server.transfer i click on the drop down list it changes to the wrong theme. IE if i click on a "green" them it changes to the red theme, etc In all scenarios the theme is never applied to any page except the page that has the ddl. Other ideas?? Thanks Quote
Administrators PlausiblyDamp Posted April 12, 2006 Administrators Posted April 12, 2006 The problem is that Server.Transfer doesn't preserve the form's data unless you specify you want it to (add an extra boolean parameter). However doing this causes an infinite loop... Bit of a dirty hack but this works for me and should get you onto the right track. Protected Sub ChangeTheme_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs) Handles ddlThemes.SelectedIndexChanged If Session("test") Is Nothing Then Session("Test") = True Session.Add("MyTheme", ddlThemes.SelectedItem.Text) Server.Transfer(Request.FilePath, True) Else Session("test") = Nothing End If End Sub Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
gtjr92 Posted April 12, 2006 Author Posted April 12, 2006 half way there changing the selected index changed event solved the dropdown list problem. However the theme is still only being applied to one page, and not site wide. If I manually change the them in the webconfig file the theme is applied properly so i must be missing something else in my code. Quote
gtjr92 Posted April 12, 2006 Author Posted April 12, 2006 got it Figured out my theme problem, i was not inheriting the basepage class to the rest of my pages DUH!! Thanks for your help! Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.