473,388 Members | 1,188 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,388 software developers and data experts.

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 2142
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: C A Upsdell | last post by:
I have a site where I am setting a style dynamically, using the JS statement: obj.style.backgroundImage = 'url(img/bak_page.jpg)'; where 'obj' is either document.getElementById(id), or...
7
by: Just Dummy | last post by:
Hi all, I am struggling with a problem for a long time. Problem statement: I have a table and the table can contain n number of rows. i.e., the table rows will be generataed out of a xml...
0
by: Diane Yocom | last post by:
I'm very new to ASP.Net and probably jumped in a little over my head, but... I'm trying to create a user control that will control navigation through my site. It's sortof like Amazon.com, where...
4
by: Bas Groeneveld | last post by:
I am developing an ASP.NET application part of which consists of a data entry wizard defined by entries in a data table - ie the controls on each page of the wizard are determined by definitions in...
4
by: Chris Mahoney | last post by:
Hi Currently I am setting the background image of my page by using the following code: <style type="text/css"> BODY { BACKGROUND-IMAGE: url(myimage.jpg) } </style> What I would like to do...
2
by: Axel Dahmen | last post by:
HI, I want to dynamically add controls to a web page from within a common base class. Unfortunately, ASP.NET fails with "System.Web.HttpException: The Controls collection cannot be modified...
12
by: Mark Rae | last post by:
Hi, It's easy enough for a child page to manipulate its MasterPage's header simply by modifying the MasterPage thus: <header runat="server"> .... .... </header>
4
by: Ed Jay | last post by:
I generate a DHTML page (a medical report) with dynamically generated text based on user input (answers to questions). The page length changes dynamically. I desire that when the page is printed...
6
by: _Who | last post by:
I use the code below to change to a style sheet that has: body { ....
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: 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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.