User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the ASP.NET section within the Web Development category of DaniWeb, a massive community of 429,994 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,396 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our ASP.NET advertiser: Lunarpages ASP Web Hosting
Views: 452 | Replies: 2
Reply
Join Date: Jul 2006
Posts: 46
Reputation: ChimpusDupus is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 0
ChimpusDupus ChimpusDupus is offline Offline
Light Poster

Applying Themes to a Whole Website

  #1  
Jun 17th, 2008
Hi,

I have several themes that can be applied to pages on a website based on a users preferences. The problem is that the only way I know how to apply a theme to a website is to set the Page.Theme object in the page's PreInit event. This requires that code be placed on each and every page's PreInit event.

Is there any way to apply a theme globally (as in to all pages in a website) in just one location, such as a master page or the global.asax?
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Jan 2008
Location: Largo Florida
Posts: 283
Reputation: serkansendur is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 24
serkansendur's Avatar
serkansendur serkansendur is offline Offline
Posting Whiz in Training

Re: Applying Themes to a Whole Website

  #2  
Jun 17th, 2008
yes you can do it via web.config file as follows :

<configuration>
<system.web>
<pages theme="yourThemeName" />
</system.web>
</configuration>
Serkan Şendur
MCAD.NET
Reply With Quote  
Join Date: Jul 2006
Posts: 46
Reputation: ChimpusDupus is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 0
ChimpusDupus ChimpusDupus is offline Offline
Light Poster

Re: Applying Themes to a Whole Website

  #3  
Jun 18th, 2008
The reason that solution would not work for me is that theme must be set based on user preferences stored in some sort of datasource, right now an XML file, and thus would have to be set programmatically (rather than through the web.config file).

The solution I found does the trick. It's code to be placed in the global.asax file, which is exactly where i wanted it to be:
  1. void Application_PreRequestHandlerExecute(object sender, EventArgs e)
  2.  
  3. {
  4.  
  5. Page page = Context.Handler as Page;
  6. String theme = "MyTheme";
  7. if (page != null)
  8.  
  9. {
  10.  
  11. page.Theme = theme;
  12.  
  13. }
  14.  
  15. }
  16.  

where the theme variable is set to the value retrieved from the XML file
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb ASP.NET Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Other Threads in the ASP.NET Forum

All times are GMT -4. The time now is 12:44 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC