Wrox Home  
Search P2P Archive for: Go

  Return to Index  

aspx thread: Changing Styles from a database


Message #1 by "Hugh McLaughlin" <hugh@k...> on Fri, 13 Sep 2002 12:35:43
Hello Everyone and thanks for your help in advance.  I am developing a 
web design template that allows a user to change the look of their 
website.  I am familiar wiht CSS and see that most ASP.Net examples show 
examples using CSS.  However, I want to create a user interface to allow 
the user to change some aspects of the sites appearance.  I would think 
this would have to be done with a database.  From there, I am unclear as 
to how this would be implemented to change the look, especailly regarding 
server controls.  Any help would be greatly appreciated.
Message #2 by "Dave Rezoski" <daverezoski@h...> on Fri, 13 Sep 2002 16:45:27 +0000
Here's one way to do it:

Where you would normally reference a css file in your style tag, reference 
an aspx page instead (<link rel="stylesheet" type="text/css" 
href="styles/genericstyle.aspx">).  This way you can populate the aspx page 
to be written with values from a database.  The cs file will retrieve the db 
values depending on user ... build your stylesheet in the cs, then add it to 
a placeholder control in the aspx page (so the rendered aspx page will look 
just like a normal css file). Now assign a class to each element or control 
within your app, as you'd normally do for applying styles.  Create an admin 
interface for editing the values in the db so your users can customize the 
interface, and it's beer-thrity for you.

HTH



----Original Message Follows----
From: "Hugh McLaughlin" <hugh@k...>
Reply-To: "ASP+" <aspx@p...>
To: "ASP+" <aspx@p...>
Subject: [aspx] Changing Styles from a database
Date: Fri, 13 Sep 2002 12:35:43

Hello Everyone and thanks for your help in advance.  I am developing a
web design template that allows a user to change the look of their
website.  I am familiar wiht CSS and see that most ASP.Net examples show
examples using CSS.  However, I want to create a user interface to allow
the user to change some aspects of the sites appearance.  I would think
this would have to be done with a database.  From there, I am unclear as
to how this would be implemented to change the look, especailly regarding
server controls.  Any help would be greatly appreciated.
---

ASP.NET 1.0 Namespace Reference with C#
http://www.wrox.com/acon11.asp?ISBN=1861007442

ASP.NET 1.0 Namespace Reference with VB.NET
http://www.wrox.com/acon11.asp?ISBN=1861007450

These books are a complete reference to the ASP.NET namespaces
for developers who are already familiar with using ASP.NET.
There is no trivial introductory material or useless .NET
hype and the presentation of the namespaces, in an easy-to use
alphabetical order ensures a user-friendly reference format.
We provide in-depth coverage of all the major ASP.NET classes,
giving you those real-world tips that the documentation doesn't
offer, and demonstrating complex techniques with simple
examples.

---




_________________________________________________________________
Join the world?s largest e-mail service with MSN Hotmail. 
http://www.hotmail.com

Message #3 by "Hugh McLaughlin" <hugh@k...> on Sun, 15 Sep 2002 14:28:21
Thanks Dave.  That solved part of the problem.  But how do you 
dynamically set the style of things like calendar controls with CSS.  Or 
must you do it programattically?


> Here's one way to do it:

Where you would normally reference a css file in your style tag, 
reference 
an aspx page instead (<link rel="stylesheet" type="text/css" 
href="styles/genericstyle.aspx">).  This way you can populate the aspx 
page 
to be written with values from a database.  The cs file will retrieve the 
db 
values depending on user ... build your stylesheet in the cs, then add it 
to 
a placeholder control in the aspx page (so the rendered aspx page will 
look 
just like a normal css file). Now assign a class to each element or 
control 
within your app, as you'd normally do for applying styles.  Create an 
admin 
interface for editing the values in the db so your users can customize 
the 
interface, and it's beer-thrity for you.

HTH



----Original Message Follows----
From: "Hugh McLaughlin" <hugh@k...>
Reply-To: "ASP+" <aspx@p...>
To: "ASP+" <aspx@p...>
Subject: [aspx] Changing Styles from a database
Date: Fri, 13 Sep 2002 12:35:43

Hello Everyone and thanks for your help in advance.  I am developing a
web design template that allows a user to change the look of their
website.  I am familiar wiht CSS and see that most ASP.Net examples show
examples using CSS.  However, I want to create a user interface to allow
the user to change some aspects of the sites appearance.  I would think
this would have to be done with a database.  From there, I am unclear as
to how this would be implemented to change the look, especailly regarding
server controls.  Any help would be greatly appreciated.
---

ASP.NET 1.0 Namespace Reference with C#
http://www.wrox.com/acon11.asp?ISBN=1861007442

ASP.NET 1.0 Namespace Reference with VB.NET
http://www.wrox.com/acon11.asp?ISBN=1861007450

These books are a complete reference to the ASP.NET namespaces
for developers who are already familiar with using ASP.NET.
There is no trivial introductory material or useless .NET
hype and the presentation of the namespaces, in an easy-to use
alphabetical order ensures a user-friendly reference format.
We provide in-depth coverage of all the major ASP.NET classes,
giving you those real-world tips that the documentation doesn't
offer, and demonstrating complex techniques with simple
examples.

---




_________________________________________________________________
Join the world?s largest e-mail service with MSN Hotmail. 
http://www.hotmail.com

Message #4 by Imar Spaanjaars <Imar@S...> on Sun, 15 Sep 2002 18:30:37 +0200
Hi Hugh,

I don't think you should set the styles dynamically; just change the 
content of the styles.

Something like:

<MyCalendar id="myCal" CssClass="MyDynamicStyle" />

Then in your CSS (aspx in this case) define MyDynamicStyle  like this for 
user A:

.MyDynamicStyle
{
         background-color : green;
}

and like this for user B

.MyDynamicStyle
{
         background-color : red;
}


etc etc, I think you get the idea.


Use Output caching aggressively for this solution. The style is likely not 
to change every 10 seconds, so you can benefit a lot from caching.

HtH

Imar


At 02:28 PM 9/15/2002 +0000, you wrote:
>Thanks Dave.  That solved part of the problem.  But how do you
>dynamically set the style of things like calendar controls with CSS.  Or
>must you do it programattically?
>
>
> > Here's one way to do it:
>
>Where you would normally reference a css file in your style tag,
>reference
>an aspx page instead (<link rel="stylesheet" type="text/css"
>href="styles/genericstyle.aspx">).  This way you can populate the aspx
>page
>to be written with values from a database.  The cs file will retrieve the
>db
>values depending on user ... build your stylesheet in the cs, then add it
>to
>a placeholder control in the aspx page (so the rendered aspx page will
>look
>just like a normal css file). Now assign a class to each element or
>control
>within your app, as you'd normally do for applying styles.  Create an
>admin
>interface for editing the values in the db so your users can customize
>the
>interface, and it's beer-thrity for you.
>
>HTH
>
>
>
>----Original Message Follows----
>From: "Hugh McLaughlin" <hugh@k...>
>Reply-To: "ASP+" <aspx@p...>
>To: "ASP+" <aspx@p...>
>Subject: [aspx] Changing Styles from a database
>Date: Fri, 13 Sep 2002 12:35:43
>
>Hello Everyone and thanks for your help in advance.  I am developing a
>web design template that allows a user to change the look of their
>website.  I am familiar wiht CSS and see that most ASP.Net examples show
>examples using CSS.  However, I want to create a user interface to allow
>the user to change some aspects of the sites appearance.  I would think
>this would have to be done with a database.  From there, I am unclear as
>to how this would be implemented to change the look, especailly regarding
>server controls.  Any help would be greatly appreciated.
>---
>
>ASP.NET 1.0 Namespace Reference with C#
>http://www.wrox.com/acon11.asp?ISBN=1861007442
>
>ASP.NET 1.0 Namespace Reference with VB.NET
>http://www.wrox.com/acon11.asp?ISBN=1861007450
>
>These books are a complete reference to the ASP.NET namespaces
>for developers who are already familiar with using ASP.NET.
>There is no trivial introductory material or useless .NET
>hype and the presentation of the namespaces, in an easy-to use
>alphabetical order ensures a user-friendly reference format.
>We provide in-depth coverage of all the major ASP.NET classes,
>giving you those real-world tips that the documentation doesn't
>offer, and demonstrating complex techniques with simple
>examples.
>
>---
>
>
>
>
>_________________________________________________________________
>Join the world's largest e-mail service with MSN Hotmail.
>http://www.hotmail.com
>
>---
>
>ASP.NET 1.0 Namespace Reference with C#
>http://www.wrox.com/acon11.asp?ISBN=1861007442
>
>ASP.NET 1.0 Namespace Reference with VB.NET
>http://www.wrox.com/acon11.asp?ISBN=1861007450
>
>These books are a complete reference to the ASP.NET namespaces
>for developers who are already familiar with using ASP.NET.
>There is no trivial introductory material or useless .NET
>hype and the presentation of the namespaces, in an easy-to use
>alphabetical order ensures a user-friendly reference format.
>We provide in-depth coverage of all the major ASP.NET classes,
>giving you those real-world tips that the documentation doesn't
>offer, and demonstrating complex techniques with simple
>examples.
>
>---


Message #5 by "Hugh McLaughlin" <hugh@k...> on Mon, 16 Sep 2002 00:49:16
Hi Imar and as always, thanks for your insight.  I am however confused.  
Are you suggesting that I hard code each of the different styles and the 
use If...Then to determine which one is applicable, or am I completely 
misunderstanding.  The page-caching idea makes a lot of sense.

One final question is how do you set the styles of server controls such 
as the calendar, i.e. Selected Day style (or maybe you can't).  Your help 
is always appreciated.  Thanks again.

Hugh


> Hi Hugh,

I don't think you should set the styles dynamically; just change the 
content of the styles.

Something like:

<MyCalendar id="myCal" CssClass="MyDynamicStyle" />

Then in your CSS (aspx in this case) define MyDynamicStyle  like this for 
user A:

.MyDynamicStyle
{
         background-color : green;
}

and like this for user B

.MyDynamicStyle
{
         background-color : red;
}


etc etc, I think you get the idea.


Use Output caching aggressively for this solution. The style is likely 
not 
to change every 10 seconds, so you can benefit a lot from caching.

HtH

Imar


At 02:28 PM 9/15/2002 +0000, you wrote:
>Thanks Dave.  That solved part of the problem.  But how do you
>dynamically set the style of things like calendar controls with CSS.  Or
>must you do it programattically?
>
>
> > Here's one way to do it:
>
>Where you would normally reference a css file in your style tag,
>reference
>an aspx page instead (<link rel="stylesheet" type="text/css"
>href="styles/genericstyle.aspx">).  This way you can populate the aspx
>page
>to be written with values from a database.  The cs file will retrieve the
>db
>values depending on user ... build your stylesheet in the cs, then add it
>to
>a placeholder control in the aspx page (so the rendered aspx page will
>look
>just like a normal css file). Now assign a class to each element or
>control
>within your app, as you'd normally do for applying styles.  Create an
>admin
>interface for editing the values in the db so your users can customize
>the
>interface, and it's beer-thrity for you.
>
>HTH
>
>
>
>----Original Message Follows----
>From: "Hugh McLaughlin" <hugh@k...>
>Reply-To: "ASP+" <aspx@p...>
>To: "ASP+" <aspx@p...>
>Subject: [aspx] Changing Styles from a database
>Date: Fri, 13 Sep 2002 12:35:43
>
>Hello Everyone and thanks for your help in advance.  I am developing a
>web design template that allows a user to change the look of their
>website.  I am familiar wiht CSS and see that most ASP.Net examples show
>examples using CSS.  However, I want to create a user interface to allow
>the user to change some aspects of the sites appearance.  I would think
>this would have to be done with a database.  From there, I am unclear as
>to how this would be implemented to change the look, especailly regarding
>server controls.  Any help would be greatly appreciated.
>---
>
>ASP.NET 1.0 Namespace Reference with C#
>http://www.wrox.com/acon11.asp?ISBN=1861007442
>
>ASP.NET 1.0 Namespace Reference with VB.NET
>http://www.wrox.com/acon11.asp?ISBN=1861007450
>
>These books are a complete reference to the ASP.NET namespaces
>for developers who are already familiar with using ASP.NET.
>There is no trivial introductory material or useless .NET
>hype and the presentation of the namespaces, in an easy-to use
>alphabetical order ensures a user-friendly reference format.
>We provide in-depth coverage of all the major ASP.NET classes,
>giving you those real-world tips that the documentation doesn't
>offer, and demonstrating complex techniques with simple
>examples.
>
>---
>
>
>
>
>_________________________________________________________________
>Join the world's largest e-mail service with MSN Hotmail.
>http://www.hotmail.com
>
>---
>
>ASP.NET 1.0 Namespace Reference with C#
>http://www.wrox.com/acon11.asp?ISBN=1861007442
>
>ASP.NET 1.0 Namespace Reference with VB.NET
>http://www.wrox.com/acon11.asp?ISBN=1861007450
>
>These books are a complete reference to the ASP.NET namespaces
>for developers who are already familiar with using ASP.NET.
>There is no trivial introductory material or useless .NET
>hype and the presentation of the namespaces, in an easy-to use
>alphabetical order ensures a user-friendly reference format.
>We provide in-depth coverage of all the major ASP.NET classes,
>giving you those real-world tips that the documentation doesn't
>offer, and demonstrating complex techniques with simple
>examples.
>
>---


Message #6 by "Imar Spaanjaars" <Imar@S...> on Mon, 16 Sep 2002 08:15:32
Hi Hugh,

Well, it depends......

The thing is, most server controls have multiple ways to influence their 
styles. First of all, they contain properties like background-color, font-
color etc etc. However, they also contain a CssClass property. This allows 
you to point to a certain CSS class (in a separate style sheet) that 
defines the layout of your control.

Personally, I like to stay away from the control properties for styles as 
much as possible, as they somehow seem to defeat the whole purpose of CSS: 
separation between content and style. They don't allow me to control the 
looks of my sites from a singe style sheet. Unfortunately, you can't 
ignore them completely as you sometimes need certain properties to 
influence the look of the control.

The idea I gave you for the dynamic styles is based on the second method 
for styles, using the CssClass. If however you need to control the direct 
style properties for controls, this method is no going to work. 

One way to solve this, is to use databinding:

    <MyControl font-color='<%# Container.DataItem("FontColor") %>' />

should work, as far as I know. The disadvantage is that you need 
formatting information in your regular dataset.

Another solution is to set styles dynamically (in code behind for example):

    MyControl.Font.Bold = bFontBold

should work as well. That way, you can retrieve the values from a database 
and set them dynamically.

Other solutions:
- When using templated controls (e.g. datagrid, datalist) you can use 
LoadControl to load controls with styles from disk dynamically. Check out 
the MSDN for more info.
- Build your complete page dynamically. If you only need to perform the 
style change once, you could generate the complete ASPX page on the fly 
with the correct styles attached. Depening on your setup, you could use 
runtime classes to compile your page yourself, or let the runtime compile 
them when they get requested the first time.

HtH


Imar




> Hi Imar and as always, thanks for your insight.  I am however confused.  
A> re you suggesting that I hard code each of the different styles and the 
u> se If...Then to determine which one is applicable, or am I completely 
m> isunderstanding.  The page-caching idea makes a lot of sense.

> One final question is how do you set the styles of server controls such 
a> s the calendar, i.e. Selected Day style (or maybe you can't).  Your 
help 
i> s always appreciated.  Thanks again.

> Hugh

Message #7 by "Dave Rezoski" <daverezoski@h...> on Mon, 16 Sep 2002 17:08:41 +0000
Hugh, I believe you should be able to apply the style programmatically like 
this:

// declare
protected System.Web.UI.WebControls.Calendar myCal;

// assign style
myCal.SelectedDayStyle.CssClass = "classname";


----Original Message Follows----
From: "Hugh McLaughlin" <hugh@k...>
Reply-To: "ASP+" <aspx@p...>
To: "ASP+" <aspx@p...>
Subject: [aspx] Re: Changing Styles from a database
Date: Mon, 16 Sep 2002 00:49:16

Hi Imar and as always, thanks for your insight.  I am however confused.
Are you suggesting that I hard code each of the different styles and the
use If...Then to determine which one is applicable, or am I completely
misunderstanding.  The page-caching idea makes a lot of sense.

One final question is how do you set the styles of server controls such
as the calendar, i.e. Selected Day style (or maybe you can't).  Your help
is always appreciated.  Thanks again.

Hugh


 > Hi Hugh,

I don't think you should set the styles dynamically; just change the
content of the styles.

Something like:

<MyCalendar id="myCal" CssClass="MyDynamicStyle" />

Then in your CSS (aspx in this case) define MyDynamicStyle  like this for
user A:

.MyDynamicStyle
{
          background-color : green;
}

and like this for user B

.MyDynamicStyle
{
          background-color : red;
}


etc etc, I think you get the idea.


Use Output caching aggressively for this solution. The style is likely
not
to change every 10 seconds, so you can benefit a lot from caching.

HtH

Imar


At 02:28 PM 9/15/2002 +0000, you wrote:
 >Thanks Dave.  That solved part of the problem.  But how do you
 >dynamically set the style of things like calendar controls with CSS.  Or
 >must you do it programattically?
 >
 >
 > > Here's one way to do it:
 >
 >Where you would normally reference a css file in your style tag,
 >reference
 >an aspx page instead (<link rel="stylesheet" type="text/css"
 >href="styles/genericstyle.aspx">).  This way you can populate the aspx
 >page
 >to be written with values from a database.  The cs file will retrieve the
 >db
 >values depending on user ... build your stylesheet in the cs, then add it
 >to
 >a placeholder control in the aspx page (so the rendered aspx page will
 >look
 >just like a normal css file). Now assign a class to each element or
 >control
 >within your app, as you'd normally do for applying styles.  Create an
 >admin
 >interface for editing the values in the db so your users can customize
 >the
 >interface, and it's beer-thrity for you.
 >
 >HTH
 >
 >
 >
 >----Original Message Follows----
 >From: "Hugh McLaughlin" <hugh@k...>
 >Reply-To: "ASP+" <aspx@p...>
 >To: "ASP+" <aspx@p...>
 >Subject: [aspx] Changing Styles from a database
 >Date: Fri, 13 Sep 2002 12:35:43
 >
 >Hello Everyone and thanks for your help in advance.  I am developing a
 >web design template that allows a user to change the look of their
 >website.  I am familiar wiht CSS and see that most ASP.Net examples show
 >examples using CSS.  However, I want to create a user interface to allow
 >the user to change some aspects of the sites appearance.  I would think
 >this would have to be done with a database.  From there, I am unclear as
 >to how this would be implemented to change the look, especailly regarding
 >server controls.  Any help would be greatly appreciated.
 >---
 >
 >ASP.NET 1.0 Namespace Reference with C#
 >http://www.wrox.com/acon11.asp?ISBN=1861007442
 >
 >ASP.NET 1.0 Namespace Reference with VB.NET
 >http://www.wrox.com/acon11.asp?ISBN=1861007450
 >
 >These books are a complete reference to the ASP.NET namespaces
 >for developers who are already familiar with using ASP.NET.
 >There is no trivial introductory material or useless .NET
 >hype and the presentation of the namespaces, in an easy-to use
 >alphabetical order ensures a user-friendly reference format.
 >We provide in-depth coverage of all the major ASP.NET classes,
 >giving you those real-world tips that the documentation doesn't
 >offer, and demonstrating complex techniques with simple
 >examples.
 >
 >---
 >
 >
 >
 >
 >_________________________________________________________________
 >Join the world's largest e-mail service with MSN Hotmail.
 >http://www.hotmail.com
 >
 >---
 >
 >ASP.NET 1.0 Namespace Reference with C#
 >http://www.wrox.com/acon11.asp?ISBN=1861007442
 >
 >ASP.NET 1.0 Namespace Reference with VB.NET
 >http://www.wrox.com/acon11.asp?ISBN=1861007450
 >
 >These books are a complete reference to the ASP.NET namespaces
 >for developers who are already familiar with using ASP.NET.
 >There is no trivial introductory material or useless .NET
 >hype and the presentation of the namespaces, in an easy-to use
 >alphabetical order ensures a user-friendly reference format.
 >We provide in-depth coverage of all the major ASP.NET classes,
 >giving you those real-world tips that the documentation doesn't
 >offer, and demonstrating complex techniques with simple
 >examples.
 >
 >---


---

ASP.NET 1.0 Namespace Reference with C#
http://www.wrox.com/acon11.asp?ISBN=1861007442

ASP.NET 1.0 Namespace Reference with VB.NET
http://www.wrox.com/acon11.asp?ISBN=1861007450

These books are a complete reference to the ASP.NET namespaces
for developers who are already familiar with using ASP.NET.
There is no trivial introductory material or useless .NET
hype and the presentation of the namespaces, in an easy-to use
alphabetical order ensures a user-friendly reference format.
We provide in-depth coverage of all the major ASP.NET classes,
giving you those real-world tips that the documentation doesn't
offer, and demonstrating complex techniques with simple
examples.

---




_________________________________________________________________
MSN Photos is the easiest way to share and print your photos: 
http://photos.msn.com/support/worldwide.aspx


  Return to Index