Changing CSS sheets from Code

  • Thread starter Thread starter T. Wong
  • Start date Start date
T

T. Wong

I want to have a single CSS style sheet control the look of my whole asp.net
application but I need to set the values in this CSS from code in the start
page as the CSS values will be stored in a data base.

First, is this possible?

Since CSS is plain text I could manipulate it all with string string
functions in code, BUT, are there any classes or functions that make it
easier to affect CSS parameters at run time?

Thank you in Advance for any Help,
T. Wong
 
Yes and no.

The issue lies in the fact that CSS is a client side script while you are
changing on server side. You can certainly dynamically output some styles,
which will solve your issue (as the cascade defaults on using page styles
first over the stylesheet), but you would be better served to create
different style sheets for different "themes" and change the stylesheet link.

NOTE: This is easier in .NET 2.0 than 1.x.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

***************************
Think Outside the Box!
***************************
 
I did not make myself clear...

I want to create new classes in Styles.css from code on the fly. My
question was: can this be done.
T.Wong
 
I did not make myself clear...

I want to create new classes in Styles.css from code on the fly. My
question was: can this be done.

While it CAN be done, the question is, SHOULD it be done?

One issue is that CSS pages are oftech cached. If you change or update
them dynamically, your client web browser will likely ignore any new
changes and use their cached versions.

You *COULD* dynamically generate new CSS pages on the fly, either by
directly writing them to disk or by using an HTTPModule (if you map css
files to be handled by aspnet). But, again, this sort of dereats the
purpose of CSS, since you're going to have a ton of cached files sitting
around.

If this is really that important, you would be better off simply
dynamically generating a "<style>" section in your web page to include your
dynamic CSS.
 

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

Back
Top