Connecting Tech Pros Worldwide Forums | Help | Site Map

Dynamically Apply CSS

Robert
Guest
 
Posts: n/a
#1: Nov 18 '05
Are there any other ways to dynamically apply CSS styling to a page (without
using inline CSS)?

I'm sure I could dynamically generate a new and uniquely named CSS file "on
the fly" when users log in, and then dynamically associate that css file
with the requested pages - but I'm looking for something much simpler and
with better runtime performance.

Here's what I'm after. I plan to let users save various preferences between
sessions. Behind the scenes I save this information with their account data
in a database. Some of these preferences include page background color and
font size - which I want to apply to their pages at runtime via CSS. There
will also be a couple of css classes to be applied to various elements in
the page.

I'm already storing all of the css settings and classes in the database, and
I'd like to leverage it all from there if possible.

Any suggestions for accomplishing this?

Thanks!



AsyaHubby
Guest
 
Posts: n/a
#2: Nov 18 '05

re: Dynamically Apply CSS


just add attributes to objects at runtime.

txt.attributes.add("Style", YourStyleStringHere)

This will render the style attribute for the input tag with the given
settings

"Robert" <A@B.COM> wrote in message
news:O60ShohdEHA.228@TK2MSFTNGP11.phx.gbl...[color=blue]
> Are there any other ways to dynamically apply CSS styling to a page[/color]
(without[color=blue]
> using inline CSS)?
>
> I'm sure I could dynamically generate a new and uniquely named CSS file[/color]
"on[color=blue]
> the fly" when users log in, and then dynamically associate that css file
> with the requested pages - but I'm looking for something much simpler and
> with better runtime performance.
>
> Here's what I'm after. I plan to let users save various preferences[/color]
between[color=blue]
> sessions. Behind the scenes I save this information with their account[/color]
data[color=blue]
> in a database. Some of these preferences include page background color and
> font size - which I want to apply to their pages at runtime via CSS. There
> will also be a couple of css classes to be applied to various elements in
> the page.
>
> I'm already storing all of the css settings and classes in the database,[/color]
and[color=blue]
> I'd like to leverage it all from there if possible.
>
> Any suggestions for accomplishing this?
>
> Thanks!
>
>[/color]


Robert
Guest
 
Posts: n/a
#3: Nov 18 '05

re: Dynamically Apply CSS


Thanks for the quick and useful response - I'll certainly use it in some
scenarios: A couple of followup questions:
1. Will this method work for the <body> element? (I definitely need to be
able to set the <body bgcolor=...>) or will this only work for server
controls?
2. Will this method let me associate a css class with the element being
styled - or am I limited only to applying inline css attributes?

Thanks!



"AsyaHubby" <asyahubby@hotmail.com> wrote in message
news:O0NcZxhdEHA.2752@TK2MSFTNGP12.phx.gbl...[color=blue]
> just add attributes to objects at runtime.
>
> txt.attributes.add("Style", YourStyleStringHere)
>
> This will render the style attribute for the input tag with the given
> settings
>
> "Robert" <A@B.COM> wrote in message
> news:O60ShohdEHA.228@TK2MSFTNGP11.phx.gbl...[color=green]
> > Are there any other ways to dynamically apply CSS styling to a page[/color]
> (without[color=green]
> > using inline CSS)?
> >
> > I'm sure I could dynamically generate a new and uniquely named CSS file[/color]
> "on[color=green]
> > the fly" when users log in, and then dynamically associate that css file
> > with the requested pages - but I'm looking for something much simpler[/color][/color]
and[color=blue][color=green]
> > with better runtime performance.
> >
> > Here's what I'm after. I plan to let users save various preferences[/color]
> between[color=green]
> > sessions. Behind the scenes I save this information with their account[/color]
> data[color=green]
> > in a database. Some of these preferences include page background color[/color][/color]
and[color=blue][color=green]
> > font size - which I want to apply to their pages at runtime via CSS.[/color][/color]
There[color=blue][color=green]
> > will also be a couple of css classes to be applied to various elements[/color][/color]
in[color=blue][color=green]
> > the page.
> >
> > I'm already storing all of the css settings and classes in the database,[/color]
> and[color=green]
> > I'd like to leverage it all from there if possible.
> >
> > Any suggestions for accomplishing this?
> >
> > Thanks!
> >
> >[/color]
>
>[/color]


Hans Kesting
Guest
 
Posts: n/a
#4: Nov 18 '05

re: Dynamically Apply CSS



"Robert" <A@B.COM> wrote in message news:O60ShohdEHA.228@TK2MSFTNGP11.phx.gbl...[color=blue]
> Are there any other ways to dynamically apply CSS styling to a page (without
> using inline CSS)?
>
> I'm sure I could dynamically generate a new and uniquely named CSS file "on
> the fly" when users log in, and then dynamically associate that css file
> with the requested pages - but I'm looking for something much simpler and
> with better runtime performance.
>
> Here's what I'm after. I plan to let users save various preferences between
> sessions. Behind the scenes I save this information with their account data
> in a database. Some of these preferences include page background color and
> font size - which I want to apply to their pages at runtime via CSS. There
> will also be a couple of css classes to be applied to various elements in
> the page.
>
> I'm already storing all of the css settings and classes in the database, and
> I'd like to leverage it all from there if possible.
>
> Any suggestions for accomplishing this?
>
> Thanks!
>
>[/color]

Instead of writing user-specific files to the filesystem, you could also
point the stylesheet to an fixed aspx file:
<link rel="stylesheet" type="text/css" href="usercss.aspx">

and serve the user-specific css code (with appropriate caching) from there.

Hans Kesting


AsyaHubby
Guest
 
Posts: n/a
#5: Nov 18 '05

re: Dynamically Apply CSS


Depends if you are using master template where you write out your own body
tag.
If you are you can easily massage the attribute of the body tag.
You can associate a class - just Object.CssClass=YourClass or you can use as
before
Object.Attributes.Add("Class",YourClass)


"Robert" <A@B.COM> wrote in message
news:uDeGv9hdEHA.3616@TK2MSFTNGP10.phx.gbl...[color=blue]
> Thanks for the quick and useful response - I'll certainly use it in some
> scenarios: A couple of followup questions:
> 1. Will this method work for the <body> element? (I definitely need to be
> able to set the <body bgcolor=...>) or will this only work for server
> controls?
> 2. Will this method let me associate a css class with the element being
> styled - or am I limited only to applying inline css attributes?
>
> Thanks!
>
>
>
> "AsyaHubby" <asyahubby@hotmail.com> wrote in message
> news:O0NcZxhdEHA.2752@TK2MSFTNGP12.phx.gbl...[color=green]
> > just add attributes to objects at runtime.
> >
> > txt.attributes.add("Style", YourStyleStringHere)
> >
> > This will render the style attribute for the input tag with the given
> > settings
> >
> > "Robert" <A@B.COM> wrote in message
> > news:O60ShohdEHA.228@TK2MSFTNGP11.phx.gbl...[color=darkred]
> > > Are there any other ways to dynamically apply CSS styling to a page[/color]
> > (without[color=darkred]
> > > using inline CSS)?
> > >
> > > I'm sure I could dynamically generate a new and uniquely named CSS[/color][/color][/color]
file[color=blue][color=green]
> > "on[color=darkred]
> > > the fly" when users log in, and then dynamically associate that css[/color][/color][/color]
file[color=blue][color=green][color=darkred]
> > > with the requested pages - but I'm looking for something much simpler[/color][/color]
> and[color=green][color=darkred]
> > > with better runtime performance.
> > >
> > > Here's what I'm after. I plan to let users save various preferences[/color]
> > between[color=darkred]
> > > sessions. Behind the scenes I save this information with their account[/color]
> > data[color=darkred]
> > > in a database. Some of these preferences include page background color[/color][/color]
> and[color=green][color=darkred]
> > > font size - which I want to apply to their pages at runtime via CSS.[/color][/color]
> There[color=green][color=darkred]
> > > will also be a couple of css classes to be applied to various elements[/color][/color]
> in[color=green][color=darkred]
> > > the page.
> > >
> > > I'm already storing all of the css settings and classes in the[/color][/color][/color]
database,[color=blue][color=green]
> > and[color=darkred]
> > > I'd like to leverage it all from there if possible.
> > >
> > > Any suggestions for accomplishing this?
> > >
> > > Thanks!
> > >
> > >[/color]
> >
> >[/color]
>
>[/color]


Closed Thread