469,931 Members | 2,694 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,931 developers. It's quick & easy.

Dynamically changing style definitions in page header

Hello all,

Hang with me, I'm a little new.

I'm working on a web application in C# using ASP.NET 2.0

The goal of my application is to have pages whose styles can be dynamically
changed based on the logged-in user's saved preferences.

The user can define their own styles (font-size, font-family, color, etc.)
for the site's pages.

Instead of creating a bunch of .css files and dynamically linking to the
right one, I wanted to use a <stylesection in each page's <headsection
that specifies the values to use for the selectors and their properties.

The values would be pulled from a database and written to this section, to
look like this:

<head>

<style type="text/css">
.testClass { color:Purple;background-color:LightGreen; }
</style>

</head>

I have been able to do this, using this syntax:

Style myStyle = new Style();

myStyle.ForeColor = System.Drawing.Color.Purple;

myStyle.BackColor = System.Drawing.Color.LightGreen;

Page.Header.StyleSheet.CreateStyleRule(myStyle, this, ".testClass");

But not every available property will have a value defined for it in my
database. Is there a way to set the property and value by name and value,
like

myStyle.SetProperty("Color","Red")

Or a better way to achieve this...?

Thanks in advance,

Jason
Mar 6 '07 #1
2 2023
Hi

did you look for something like

myStyle.Add("background-color", "silver");

this way you'd set new value to the "background-color"

is this what you where looking for ?

Adlai
--
-------------------------------------
If my answer helped you please press "Yes" bellow

אם תשובה זו עזרה לך, א*א הצבע "כן"

Adlai Maschiach
http://blogs.microsoft.co.il/blogs/adlaim/
"Jason_SanDiego2006" wrote:
Hello all,

Hang with me, I'm a little new.

I'm working on a web application in C# using ASP.NET 2.0

The goal of my application is to have pages whose styles can be dynamically
changed based on the logged-in user's saved preferences.

The user can define their own styles (font-size, font-family, color, etc.)
for the site's pages.

Instead of creating a bunch of .css files and dynamically linking to the
right one, I wanted to use a <stylesection in each page's <headsection
that specifies the values to use for the selectors and their properties.

The values would be pulled from a database and written to this section, to
look like this:

<head>

<style type="text/css">
.testClass { color:Purple;background-color:LightGreen; }
</style>

</head>

I have been able to do this, using this syntax:

Style myStyle = new Style();

myStyle.ForeColor = System.Drawing.Color.Purple;

myStyle.BackColor = System.Drawing.Color.LightGreen;

Page.Header.StyleSheet.CreateStyleRule(myStyle, this, ".testClass");

But not every available property will have a value defined for it in my
database. Is there a way to set the property and value by name and value,
like

myStyle.SetProperty("Color","Red")

Or a better way to achieve this...?

Thanks in advance,

Jason
Mar 6 '07 #2
I am not sure it can be done. In any case you can always put a placeholder
in the page header and fill it up with the correct style definitions in
runtime without using the Style class.

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net
"Jason_SanDiego2006" <ja*****@hotmail.comwrote in message
news:%2****************@TK2MSFTNGP05.phx.gbl...
Hello all,

Hang with me, I'm a little new.

I'm working on a web application in C# using ASP.NET 2.0

The goal of my application is to have pages whose styles can be
dynamically changed based on the logged-in user's saved preferences.

The user can define their own styles (font-size, font-family, color, etc.)
for the site's pages.

Instead of creating a bunch of .css files and dynamically linking to the
right one, I wanted to use a <stylesection in each page's <headsection
that specifies the values to use for the selectors and their properties.

The values would be pulled from a database and written to this section, to
look like this:

<head>

<style type="text/css">
.testClass { color:Purple;background-color:LightGreen; }
</style>

</head>

I have been able to do this, using this syntax:

Style myStyle = new Style();

myStyle.ForeColor = System.Drawing.Color.Purple;

myStyle.BackColor = System.Drawing.Color.LightGreen;

Page.Header.StyleSheet.CreateStyleRule(myStyle, this, ".testClass");

But not every available property will have a value defined for it in my
database. Is there a way to set the property and value by name and value,
like

myStyle.SetProperty("Color","Red")

Or a better way to achieve this...?

Thanks in advance,

Jason

Mar 6 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by C A Upsdell | last post: by
7 posts views Thread by Just Dummy | last post: by
reply views Thread by Diane Yocom | last post: by
4 posts views Thread by Bas Groeneveld | last post: by
4 posts views Thread by Chris Mahoney | last post: by
6 posts views Thread by _Who | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.