473,769 Members | 3,828 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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;ba ckground-color:LightGree n; }
</style>

</head>

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

Style myStyle = new Style();

myStyle.ForeCol or = System.Drawing. Color.Purple;

myStyle.BackCol or = System.Drawing. Color.LightGree n;

Page.Header.Sty leSheet.CreateS tyleRule(myStyl e, 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.SetProp erty("Color","R ed")

Or a better way to achieve this...?

Thanks in advance,

Jason
Mar 6 '07 #1
2 2167
Hi

did you look for something like

myStyle.Add("ba ckground-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_SanDiego 2006" 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;ba ckground-color:LightGree n; }
</style>

</head>

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

Style myStyle = new Style();

myStyle.ForeCol or = System.Drawing. Color.Purple;

myStyle.BackCol or = System.Drawing. Color.LightGree n;

Page.Header.Sty leSheet.CreateS tyleRule(myStyl e, 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.SetProp erty("Color","R ed")

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_SanDiego 2006" <ja*****@hotmai l.comwrote in message
news:%2******** ********@TK2MSF TNGP05.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;ba ckground-color:LightGree n; }
</style>

</head>

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

Style myStyle = new Style();

myStyle.ForeCol or = System.Drawing. Color.Purple;

myStyle.BackCol or = System.Drawing. Color.LightGree n;

Page.Header.Sty leSheet.CreateS tyleRule(myStyl e, 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.SetProp erty("Color","R ed")

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
2890
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 document.all, depending on browser support. This works just fine, with just one small problem: I want to set the style ONLY for screen media, not for printer media; the above statement appears to
7
3083
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 using a xslt. Now the problem is I want the table to be only with a height of 200px. if this exceeds beyond 200px, a vertical scroll bar along should appear. The horizontal
0
3175
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 there are tabs at the top with "submenu" buttons showing below the selected tab. The data that defines the tabs and submenus is stored in an XML file and I'm using nested repeaters to build them dynamically. I've got it working pretty well, except...
4
2499
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 the table. I know that I can dynamically add controls (eg a textbox) to the page controls collection of a web form in a server event which will then be rendered onto the form, as in the following snippet: System.Web.UI.WebControls.TextBox...
4
3786
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 is change the background image dynamically. My guess
2
7364
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 because the control contains code blocks (i.e. <% ... %>)." All of my pages contain these kind of blocks, for several reasons. For one, I don't know any other way to dynamically add header information like e.g. style sheet links to a web page. So, is...
12
4931
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
3647
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 and reaches a specific length, it terminates printing that page, prints a page number, and then begins to print the next page using the same header and format as the previous page. The page uses no tables or paragraph elements, only CSS. IOW, I...
6
2559
by: _Who | last post by:
I use the code below to change to a style sheet that has: body { ....
0
9579
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, well explore What is ONU, What Is Router, ONU & Routers main usage, and What is the difference between ONU and Router. Lets take a closer look ! Part I. Meaning of...
0
10205
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10035
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9984
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9851
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8863
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development projectplanning, coding, testing, and deploymentwithout human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7401
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupr who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5293
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3556
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.