Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Feb 26, 2009 05:20 AM by babuji_godem
May 04, 2007 09:07 PM|LINK
I have multiple master pages and I was wonder how do you dynamically change the theme for the entire site upon user selection (dropdownlist).
Ex. I have template.master which is only used for the default.aspx page. I have subtemplate.master for all subsequent pages. The dropdownlist for theme selection is on the default.aspx page.
My web.config has this line of code assigning the default template:
When I try to put the code for changing the theme on the preinit of default.aspx, it only changes the theme of the default.aspx page and none of the others (which use a different master page).
Any help is appreciated.
May 04, 2007 10:12 PM|LINK
U can try the method descibed here (http://www.codeproject.com/useritems/dynamicThemes.asp).
Make a base page and let all of your other pages inherit that one. Hope that does the trick for ya.
May 04, 2007 10:23 PM|LINK
You will have to find a way to persist the theme selection across pages.
I will recommend you create a PageBase class inherite from the Page class, and have all your pages in your site inherited from this PageBase class.
In the PreIn of your PageBase class, can use a cookie, session state or other logic to store the theme selection. My following example, in C#, assumes that you have a cookie set for the desired theme.
protected override void OnPreInit(EventArgs e)
if (Request.Cookies["theme"] != null)
this.Theme = Request.Cookies["theme"].Value;
Theme Dynamically Changing a theme
May 05, 2007 08:42 AM|LINK
May 07, 2007 08:50 PM|LINK
Thanks for your response. I found your similar response to another question here:
http://forums.asp.net/thread/1649475.aspx. I don't program using C#, only VB... can you "translate" this for me? I've tried but can't seem to figure it out. Thanks!
May 08, 2007 10:14 AM|LINK
May 08, 2007 12:56 PM|LINK
If you want to persist a theme, the best way (I think) is to use the asp.net personalization Profile which caters for Anynomouse users.
Feb 26, 2009 05:20 AM|LINK
You can write a method (which overrides the Style Sheet) in a class file which is inherited by all the content page.
Here is a good example, you try it