CodeVerge.Net Beta


   Explore    Item Entry   Register  Login  
Microsoft News
Asp.Net Forums
IBM Software
Borland Forums
Adobe Forums
Novell Forums




Can Reply:  No Members Can Edit: No Online: Yes
Zone: > NEWSGROUP > Asp.Net Forum > general_asp.net.master_pages_themes_and_navigation_controls Tags:
Item Type: NewsGroup Date Entered: 4/6/2006 5:38:45 PM Date Modified: Subscribers: 0 Subscribe Alert
Rate It:
NR
XPoints: N/A Replies: 4 Views: 417 Favorited: 0 Favorite
5 Items, 1 Pages 1 |< << Go >> >|
gtjr921
Asp.Net User
using drop down list to programatically change themes4/6/2006 5:38:45 PM

0

I have created an objectds theme manager which gets the themes based on the app_themes directory folders. I have a class theme and  drop down list that I want to populate with the theme names.
Instead my dropdown list gets populated with the word "Theme" 8 times which is how many folders there are under my app_themes folder when I click on any of those the page postbacks but the themes is not changed.  I do not get any errors when running this.
here is my code

'code to find folders in app_themes

Public

Class ThemeManager

Public Shared Function GetThemes() As List(Of Theme)

Dim themeInfo As DirectoryInfo = New DirectoryInfo(System.Web.HttpContext.Current.Server.MapPath("App_Themes"))

Dim Info2() As DirectoryInfo = themeInfo.GetDirectories()

Dim list As List(Of Theme) = New List(Of Theme)

Dim DirInfo As DirectoryInfo

For Each DirInfo In Info2

Dim themeName As Theme = New Theme(DirInfo.Name)

list.Add(themeName)

Next

Return list

End Function

------------

'Theme Class

Public
Class Theme

Private _name As String

Public Property Name() As String

Get

Return _name

End Get

Set(ByVal Value As String)

_name = Value

End Set

End Property

Public Sub New(ByVal name As String)

name = name

End Sub

End

Class

'asp code

<asp:DropDownList ID="ddlThemes" runat="server"

AutoPostBack="True" DataSourceID="ThemeODS" OnDataBound="ThemesDataBound" >

</asp:DropDownList >

<

asp:ObjectDataSource ID="ThemeODS" runat="server"

SelectMethod="GetThemes" TypeName="ThemeManager" ></asp:ObjectDataSource>

'code for ddrop down and object data souce

Protected

Sub ThemesDataBound(ByVal sender As Object, ByVal e As EventArgs)

ddlThemes.SelectedItem.Text = Page.Theme

End Sub

Protected Sub ddlthemeSelect(ByVal sender As Object, ByVal e As EventArgs) Handles ddlthemes.selectedindexchanged

Session.Add(

"MyTheme", ddlThemes.SelectedItem.Text)

Server.Transfer(Request.FilePath)

End Sub

 
dannychen
Asp.Net User
Re: using drop down list to programatically change themes4/6/2006 10:27:25 PM

0

There are a couple issues here. 

1) You sould set the DataTextField and DataValueFields for your DropDownList to the properties in your Theme object otherwise it doesn't know what fields to use.

2) I don't see any code that would actually set the current theme.  This would be some kind of logic you put in PreInit.  Here's a link for more info on programatically setting themes. http://www.asp.net/QuickStart/aspnet/doc/themes/personalization.aspx#code

--
Danny


disclaimer: Information provided is 'as is' and conveys no warranties or guarantees.
gtjr921
Asp.Net User
Re: using drop down list to programatically change themes4/7/2006 1:54:45 AM

0

well I did set the current theme under the basepage class i inherited it in my codebehind for my other pages. like this

Public Class BasePage
    
Inherits System.Web.UI.Page
    
    
Protected Overrides Sub OnPreInit(ByVal As EventArgs)
        
MyBase.OnPreInit(e)
        
If (Session("MyTheme"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

 

did i really miss the drop down that bad? guess im not awake. I need to set it like datatextfield="theme"

right?

 

 



gtjr921
Asp.Net User
Re: using drop down list to programatically change themes4/7/2006 2:33:09 PM

0

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

 

 

dannychen
Asp.Net User
Re: using drop down list to programatically change themes4/7/2006 4:33:02 PM

0

The item isn't being selected properly because you are using "SelectedItem"  If you look in intellisense you would see that this is a readonly property.  The correct way to set a selected item in a DropDownList is to set the "SelectedIndex" properly.  In order do to this you will need to determine from the list of items which one matches the current theme and set that as the selected index.

--
Danny


disclaimer: Information provided is 'as is' and conveys no warranties or guarantees.
5 Items, 1 Pages 1 |< << Go >> >|


Free Download:

Books:
Core Internet Application Development with ASP.NET 2.0 Authors: Randy Connolly, Pages: 1049, Published: 2007
Designing Online Identities: Successful Graphic Strategies for Brands on the Web Authors: Clay Andres, Pages: 192, Published: 2002
Identity Design Sourcebook: Successful IDs Deconstructed and Revealed Authors: Clay Andres, Catharine M. Fishel, Pat Matson Knapp, Pages: 350, Published: 2004
Learning ASP.NET 3.5 Authors: Jesse Liberty, Dan Hurwitz, Brian MacDonald, Pages: 576, Published: 2008
A First Look at ASP.NET V. 2.0 Authors: Alex Homer, Dave Sussman, Rob Howard, Pages: 498, Published: 2004
ASP. NET V. 2. 0-the Beta Version: The Beta Version Authors: Alex Homer, Dave Sussman, Rob Howard, Pages: 620, Published: 2004
Expert F# Authors: Don Syme, Adam Granicz, Antonio Cisternino, Pages: 609, Published: 2007

Web:
using drop down list to programatically change themes - ng.asp-net ... Apr 6, 2006 ... using drop down list to programatically change themes, > ROOT > NEWSGROUP > Asp. Net Forum ...
Changing Theme Properties Programmatically in Microsoft FrontPage 2000 Although you can change several theme properties programmatically, .... An easy way to do this is to populate a drop-down list with all available, ...
Adventures in C#: Loading themes programmatically In a nutshell, the best way to programmatically change themes is to create ... To select which theme to load, I placed a DropDownList in the header section ...
K. Scott Allen : Setting An ASP.NET Theme in the PreInit Event Handler I can make a list of available themes in a DropDownList control. .... is NOT possible to change the APPLICATION'S theme programmatically via a user's input. ...
How to programatically change color of DropDownList Items - ASP ... How to programatically change color of DropDownList Items ... I am trying to create a Drop Down List that uses a datareader as its ...
InformIT: Customizing and Managing Your Site's Appearance with ASP ... One way is to simply assign the theme using the Theme=themeName in the Page ..... The example page contains a drop-down list that allows the user to select ...
Customizing and Managing Your Site's Appearance / Part 3 - Page 2 You may recall back in Listing 6.4, you programmatically set the theme of a page within .... and a DropDownList that allows the user to change the theme. ...
Dynamically change the alignment of drop down list in web form ... However, the drop down list appears but the alignment is weird. Is there any way to change the alignment programatically in the ...
Accessing themes/skinid's programmatically using asp.net 2.0 Apr 30, 2008 ... Creating an Excel Spreadsheet programmatically using VB.NET .... On index.aspx I have drop-down to select theme which you want, ...
Accessing Themes/SkinId's Programmatically using ASP.Net 2.0 Apr 17, 2007 ... NET 2.0/3.5 » Accessing Themes/SkinId's Programmatically using ASP. .... On index.aspx I have drop-down to select theme which you want, ...






templates vs themes and skins?

custom sqlsitemapprovider - menu sometimes not rendering at all

sub domain master page help

browser-specific master pages issue

background-image not displaying in table cell

extending pure css layout for menus beyond 2nd level

how can i create new object of page when it requested with different parameters?

problem with masterpage

can't have all three? menu with background image + text with mouseover effect + dropdown submenu??

wizard control onfinishbuttonclick

custom attribute in sitemap

masterpage error: make sure that the class defined in this code file matches the 'inherits' attribute, and that it extends the correct base class (e.g. page or usercontrol).

2 questions on web.sitemap

invalid cast to masterpage type

master page properties and nested masters

standard menu control + staticitemtemplate = click disabled...

treeview in master page

dynamic popout menu render beneath contentplaceholder

menu

unable to reach the menuitemclick event handler

dynamic menu item direction...

multiple content

replace navigation sub-menu on the fly

how do i use findcontrol to locate a usercontrol located in a masterpage?

how to bind javascript code to a treeview node ?

some problems with master pages

how to show html pages inside a content placeholder

page does not fully load masterpage when doing url rewriting

menu control with javascript disabled

selecting a selected treeview-node ?

   
  Privacy | Contact Us
All Times Are GMT