473,789 Members | 2,931 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Anyone Setting Themes from Master Page

I want to dynamically set my site's theme based on a setting stored in my
database.

I just hooked this up but get an error that the theme can only be set in the
page's PreInit event or earlier. However, it appears that Master pages do
not have PreInit events.

I REALLY do not want to have to stick the same code in each and every page I
create. How are you folks dynamically setting themes from master pages?

Thanks.

Jonathan

Jun 27 '08 #1
8 1899
You could make every page inherit from a base class with the code you want
in the pre init event.
"Jonathan Wood" <jw***@softcirc uits.comwrote in message
news:ej******** *******@TK2MSFT NGP04.phx.gbl.. .
>I want to dynamically set my site's theme based on a setting stored in my
database.

I just hooked this up but get an error that the theme can only be set in
the page's PreInit event or earlier. However, it appears that Master pages
do not have PreInit events.

I REALLY do not want to have to stick the same code in each and every page
I create. How are you folks dynamically setting themes from master pages?

Thanks.

Jonathan

Jun 27 '08 #2
Why don't you just set it in the web.config, for the whole site?

David Wier
http://aspnet101.com
http://iWritePro.com - One click PDF, convert .doc/.rtf/.txt to HTML with no
bloated markup
"Jonathan Wood" <jw***@softcirc uits.comwrote in message
news:ej******** *******@TK2MSFT NGP04.phx.gbl.. .
>I want to dynamically set my site's theme based on a setting stored in my
database.

I just hooked this up but get an error that the theme can only be set in
the page's PreInit event or earlier. However, it appears that Master pages
do not have PreInit events.

I REALLY do not want to have to stick the same code in each and every page
I create. How are you folks dynamically setting themes from master pages?

Thanks.

Jonathan

Jun 27 '08 #3
Check out K. Scott Allen's great articles with good sample code :

http://odetocode.com/Blogs/scott/arc...2/09/2604.aspx
http://www.odetocode.com/Articles/450.aspx

Rick Strahl has an alternate method :
http://www.west-wind.com/WebLog/posts/4899.aspx

Also, you could set the global theme in web.config:

<configuratio n>
<system.web>
<pages theme="ThemeNam e" />
</system.web>
</configuration>


Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
=============== =============== ========
"Jonathan Wood" <jw***@softcirc uits.comwrote in message news:ej******** *******@TK2MSFT NGP04.phx.gbl.. .
>I want to dynamically set my site's theme based on a setting stored in my database.

I just hooked this up but get an error that the theme can only be set in the page's PreInit event or earlier. However,
it appears that Master pages do not have PreInit events.

I REALLY do not want to have to stick the same code in each and every page I create. How are you folks dynamically
setting themes from master pages?

Thanks.

Jonathan

Jun 27 '08 #4
Because that won't help me change it dynamically.

--
Jonathan Wood
SoftCircuits Programming
http://www.softcircuits.com

"David Wier" <dw@dw.comwro te in message
news:uG******** ******@TK2MSFTN GP04.phx.gbl...
Why don't you just set it in the web.config, for the whole site?

David Wier
http://aspnet101.com
http://iWritePro.com - One click PDF, convert .doc/.rtf/.txt to HTML with
no bloated markup
"Jonathan Wood" <jw***@softcirc uits.comwrote in message
news:ej******** *******@TK2MSFT NGP04.phx.gbl.. .
>>I want to dynamically set my site's theme based on a setting stored in my
database.

I just hooked this up but get an error that the theme can only be set in
the page's PreInit event or earlier. However, it appears that Master
pages do not have PreInit events.

I REALLY do not want to have to stick the same code in each and every
page I create. How are you folks dynamically setting themes from master
pages?

Thanks.

Jonathan

Jun 27 '08 #5
It's a reasonable suggestion, but would still require that I go back and
modify each and every page created so far. I'll leave this as second choice
but am looking into more of a global handler approach if possible.

Jonathan

"Rain" <me@myplace.com wrote in message
news:e2******** ******@TK2MSFTN GP05.phx.gbl...
You could make every page inherit from a base class with the code you want
in the pre init event.
"Jonathan Wood" <jw***@softcirc uits.comwrote in message
news:ej******** *******@TK2MSFT NGP04.phx.gbl.. .
>>I want to dynamically set my site's theme based on a setting stored in my
database.

I just hooked this up but get an error that the theme can only be set in
the page's PreInit event or earlier. However, it appears that Master
pages do not have PreInit events.

I REALLY do not want to have to stick the same code in each and every
page I create. How are you folks dynamically setting themes from master
pages?

Thanks.

Jonathan

Jun 27 '08 #6
Juan,
Check out K. Scott Allen's great articles with good sample code :

http://odetocode.com/Blogs/scott/arc...2/09/2604.aspx
http://www.odetocode.com/Articles/450.aspx

Rick Strahl has an alternate method :
http://www.west-wind.com/WebLog/posts/4899.aspx
Thanks, these look like good references.
Also, you could set the global theme in web.config:

<configuratio n>
<system.web>
<pages theme="ThemeNam e" />
</system.web>
</configuration>
I'm doing this now. But this doesn't help me change it dynamically.

Jonathan

Jun 27 '08 #7
There is no work-around in this context Jonathan. We MUST use a base class
that each page inherits from.
"Jonathan Wood" <jw***@softcirc uits.comwrote in message
news:uy******** ******@TK2MSFTN GP03.phx.gbl...
It's a reasonable suggestion, but would still require that I go back and
modify each and every page created so far. I'll leave this as second
choice but am looking into more of a global handler approach if possible.

Jonathan

"Rain" <me@myplace.com wrote in message
news:e2******** ******@TK2MSFTN GP05.phx.gbl...
>You could make every page inherit from a base class with the code you
want in the pre init event.
"Jonathan Wood" <jw***@softcirc uits.comwrote in message
news:ej******* ********@TK2MSF TNGP04.phx.gbl. ..
>>>I want to dynamically set my site's theme based on a setting stored in my
database.

I just hooked this up but get an error that the theme can only be set in
the page's PreInit event or earlier. However, it appears that Master
pages do not have PreInit events.

I REALLY do not want to have to stick the same code in each and every
page I create. How are you folks dynamically setting themes from master
pages?

Thanks.

Jonathan

Jun 27 '08 #8
Actually... that's not quite true. In fact, I was able to implement my own
IHttpModule class that handles themes for all pages globally, without
needing to modify each page.

Jonathan

"clintonG" <no****@nowhere .comwrote in message
news:Oq******** ******@TK2MSFTN GP03.phx.gbl...
There is no work-around in this context Jonathan. We MUST use a base class
that each page inherits from.
"Jonathan Wood" <jw***@softcirc uits.comwrote in message
news:uy******** ******@TK2MSFTN GP03.phx.gbl...
>It's a reasonable suggestion, but would still require that I go back and
modify each and every page created so far. I'll leave this as second
choice but am looking into more of a global handler approach if possible.

Jonathan

"Rain" <me@myplace.com wrote in message
news:e2******* *******@TK2MSFT NGP05.phx.gbl.. .
>>You could make every page inherit from a base class with the code you
want in the pre init event.
"Jonathan Wood" <jw***@softcirc uits.comwrote in message
news:ej****** *********@TK2MS FTNGP04.phx.gbl ...
I want to dynamically set my site's theme based on a setting stored in
my database.

I just hooked this up but get an error that the theme can only be set
in the page's PreInit event or earlier. However, it appears that Master
pages do not have PreInit events.

I REALLY do not want to have to stick the same code in each and every
page I create. How are you folks dynamically setting themes from master
pages?

Thanks.

Jonathan
Jun 27 '08 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
1535
by: Ryan Ternier | last post by:
I have just started playing around with ASP.NET 2.0 and have a few questions I couldn't get answers to on the net. If anyone could help me with these it'd be awesome. --- Themes - THey seem to lack full functionality with CSS files. I have a theme set up. Inside that theme I can have 32 CSS files. Each file is for each page within that theme. Why? I find it easier having multiple small CSS files to work with rather than a few HUGE...
1
1339
by: Seefor | last post by:
I may be missing something, but why aren't master pages part of themes? i.e. why don't they go in the App_Themes or global Themes directory, and be referenced just by name (not full path) in the declaration for a page? That way, you can change the complete layout by just applying the theme to a page or a whole site. I know that if your master pages are XHTML, then you can change the layout significantly with CSS, but there are...
3
7067
by: johannblake | last post by:
I'm reading up on Themes and Master Pages in ASP.NET 2.0 but I cannot seem to understand what the difference between the two are. Do Master Pages essentially end up doing what Themes do? Is Themes an older part of the .NET architecutre and simply included for backward compatibility or are Themes and Master Pages two different things meant to compliment each other? Can someone give me some insight please.
2
2654
by: suresh.csharp | last post by:
Hi, I have created two themes in our application. Trying to apply themes on fly to the entire application(all pages..) . 1. In web.config file mentioned <pages theme="theme1" />, It is applying for the entire site. 2. In each Page, PreInit event menthod if I mention Page.Theme = Profile.MyTheme; It is applying the theme to which ever pages, I have declared PreInit method with above code.
4
1685
by: Sean | last post by:
My experience now working with master pages on and off for 6 months is that they can be very dangerous when working with themes. One example in particular is the changes I made to my banner menu which now work just fine with all my themes on my development machine but on my production server my non-standard themes are showing effects that are no longer in place even with a complete re-copy of my project. Problems like this with...
6
2495
by: Clinton Farleigh | last post by:
Hi, I was going to ask a question, but I think I've answered it so now I am going to rant about how crappy ASP.NET themes are instead. As I've indicated above, my problem today is with themes. Per microsoft "Only one theme can be applied to each page. You cannot apply multiple themes to a page, unlike style sheets where multiple style sheets can be applied."
11
6621
by: New Bee | last post by:
Hi, I have been looking at Themes and Skins today and now resonably understand how they work at a ground level. But I have a couple of questions. 1. ) StyleSheetTheme I dont understand where this would be used. As I understand it the precidence is like this.
0
270
by: Stacey Levine | last post by:
I am trying to develop an intranet site and thought I would use Master Pages and themes. I found the the MS templates at http://msdn2.microsoft.com/en-us/asp.net/aa336613.aspx and was trying to set everything up. I created a Master page with three containers: header, content, footer. I created another page and put a few things in the content container. I set the theme option in the web.config. It appears to be applying the theme to the...
2
1771
by: mike | last post by:
Hi. I am having trouble grasping the concept of applying a consistent theme to an ASP.net website. I didn't used to like ASP because it was too hard to apply a theme from a common theme folder like I could do easily in PHP, but now I see that it has some nicer theming features and master files. So I want to use web.config to switch which theme I'm using, and I want to be able to have several themes. My understanding of themes is that I...
0
9666
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9511
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10410
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10139
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9020
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7529
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6769
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5418
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5551
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.