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:
<pages
theme="TemplateMonster">
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).
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.
I think you must use WebConfigurationManager, for change settings in your web.config file instead. It will affect your whole site. Read
How to: Access ASP.NET Configuration Settings Programmatically in your local Web Developer help section for details.
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!
Zhao Ji Ma
Sincerely,
Microsoft Online Community Support
“Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread. ”
mandercruso
Member
19 Points
68 Posts
Change theme dynamically on multiple master pages...
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:
<pages theme="TemplateMonster">
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.
Thanks,
Amanda
AsinuS
Member
84 Points
23 Posts
Re: Change theme dynamically on multiple master pages...
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.
Grts
himawari
Member
328 Points
63 Posts
Re: Change theme dynamically on multiple master pages...
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; } base.OnPreInit(e); }Theme Dynamically Changing a theme Cookie
Sergey Egoro...
Member
136 Points
28 Posts
Re: Change theme dynamically on multiple master pages...
May 05, 2007 08:42 AM|LINK
mandercruso
Member
19 Points
68 Posts
Re: Change theme dynamically on multiple master pages...
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!
Amanda
Zhao Ji Ma -...
All-Star
23104 Points
2380 Posts
Re: Change theme dynamically on multiple master pages...
May 08, 2007 10:14 AM|LINK
Sincerely,
Microsoft Online Community Support
“Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread. ”
ausidevelope...
Member
192 Points
43 Posts
Re: Change theme dynamically on multiple master pages...
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.
http://msdn.microsoft.com/msdnmag/issues/05/10/CuttingEdge/
Regards
babuji_godem
Member
109 Points
57 Posts
Re: Change theme dynamically on multiple master pages...
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
http://www.vikramlakhotia.com/Dynamically_changing_themes_and_applying_styles_in_aspnet_20.aspx
Human Logic Pvt Ltd.