473,385 Members | 1,693 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Dynamically Apply CSS

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!
Nov 18 '05 #1
4 1790
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:O6*************@TK2MSFTNGP11.phx.gbl...
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!

Nov 18 '05 #2
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" <as*******@hotmail.com> wrote in message
news:O0**************@TK2MSFTNGP12.phx.gbl...
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:O6*************@TK2MSFTNGP11.phx.gbl...
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!


Nov 18 '05 #3

"Robert" <A@B.COM> wrote in message news:O6*************@TK2MSFTNGP11.phx.gbl...
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!


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
Nov 18 '05 #4
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:uD**************@TK2MSFTNGP10.phx.gbl...
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" <as*******@hotmail.com> wrote in message
news:O0**************@TK2MSFTNGP12.phx.gbl...
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:O6*************@TK2MSFTNGP11.phx.gbl...
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!



Nov 18 '05 #5

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

Similar topics

0
by: alex | last post by:
I'm new to xslt, and I am attempting to use it to produce a comma-separated-value file from a large, dynamically-generated data file formatted in xml (examples of the xml file and my xslt style...
2
by: Kimmo | last post by:
Folks, I have a XML document that has been put together from a "dynamic part" (generated somehow during runtime) and a "static part" (read from a control file). Basically the document looks like...
5
by: Tim Mulholland | last post by:
I am trying to create an ASPX page that, based on QueryString inputs, returns another file, in this case a WMA file. I do not want to do this by redirect, because these files are not available...
1
by: Nathan Sokalski | last post by:
I have a User Control (.ascx & .ascx.vb) for which I need to dynamically specify certain CSS stylesheet properties. Because the controls that I use in the .ascx file do not list style as one of...
5
by: Chris Lieb | last post by:
I am trying to add an event listener to the keyup event for some text inputs that I am creating dynamically. I have no problems getting it to work in Firefox, but IE just ignores them. I have...
2
by: Yarik | last post by:
Hello, I am not sure the subject of my post adequately describes the problem I am trying to solve, so I think a specific example would be helpful. Let's say there are XML descriptions of...
4
by: assgar | last post by:
Hi I am stuck on a problem. I use 3 scripts(form, function and process). Development on win2003 server. Final server will be linux Apache,Mysql and PHP is being used. The form displays...
6
by: Bjorn Sagbakken | last post by:
Hello In VS2005: I am adding buttons and textboxes dynamically into a table, that also dynamically expands. So far, so good, actually very nice. But I am having trouble starting the desired...
2
by: djnokturnal | last post by:
Hey guys / gals, First time posting and of course I am sure it is something that has been answered 100 times but for some reason I just cant find the answer :) First off here is the structure...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...

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.