Create CSS StyleSheet at runtime

S

shapper

Hello,

How to create a CSS StyleSheet at runtime and added it an Asp:Label?
I am using Asp.Net 2.0.

Thanks,
Miguel
 
M

Mark Rae

How to create a CSS StyleSheet at runtime and added it an Asp:Label?

Do you actually need to create an entire cascading stylesheet, or do just
need to apply some style(s) to an individual Label control...?
 
S

shapper

I need to create the stylesheet at runtime.

To aply the style to the label I would do MyLabel.CssClass =
"MyStyleSheet"
This part is easy.

The reason why I asked how to apply it is because I am not sure if
something changes when the stylesheet is created at runtime.

Anyway, do you know how to create the stylesheet at runtime?

And one more thing: what about adding the stylesheet, created at
runtime, to an existing CSS file?

Thanks,
Miguel
 
M

Mark Rae

I need to create the stylesheet at runtime.
Wow!

Anyway, do you know how to create the stylesheet at runtime?

Same way you would create any other text file:
http://aspalliance.com/152_How_to_Create_a_text_file_in_ASP_NET_
And one more thing: what about adding the stylesheet, created at
runtime, to an existing CSS file?

Well, you'd have to open the existing CSS file, append the text from the
newly created CSS file into it, and save the existing CSS file.

Are you *really* sure you want to do this...?
 
G

gerry

I have used dynamic stylesheets in a few places, it goes something like this
:

create the style sheet data - cache it somewhere -
session/application/cache/disk/...
reference the stylesheet in your page
write an http handler to catch the request for the stylesheet, retreive it
from the appropriate cache and serve it back.

of course if you are writing the .css to disk then the handler isn't
necesarily required
 
M

Mark Rae

control.style.add("thestyle","the value")

:)

The OP is trying to create an entirely new cascading stylesheet file, and
then merge it with an existing stylesheet file...

At least, that's what he says he's trying to do...
 

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

Top