Anyone Setting Themes from Master Page

J

Jonathan Wood

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
 
R

Rain

You could make every page inherit from a base class with the code you want
in the pre init event.
 
J

Jonathan Wood

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
 
J

Jonathan Wood

Juan,

Thanks, these look like good references.
Also, you could set the global theme in web.config:

<configuration>
<system.web>
<pages theme="ThemeName" />
</system.web>
</configuration>

I'm doing this now. But this doesn't help me change it dynamically.

Jonathan
 
C

clintonG

There is no work-around in this context Jonathan. We MUST use a base class
that each page inherits from.
 
J

Jonathan Wood

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top