A Deeper Look at Personalization using Visual Basic 2005 - Themes and Skins (Page 4 of 4 )
Many users like to personalize their favorite web sites by setting the look and feel to meet their own aesthetic preferences. ASP.NET 2.0 supports that requirement with “themes.”
A theme is a collection of skins. A skin describes how a control should look. A skin can define style sheet attributes, images, colors, and so forth.
Having multiple themes allows your users to choose how they want your site to look by switching from one set of skins to another at the touch of a button. Combined with personalization, your site can remember the look and feel each user prefers.
There are two types of themes. The first, called stylesheet themes, define styles that may be overridden by the page or control. These are, essentially, equivalent to CSS style sheets. The second type, called customization themes, cannot be overridden. You set a stylesheet theme by adding the StyleSheetTheme attribute to the page directive, and, similarly, you set a customization theme by setting the Theme attribute in the page directive.
In any given page, the properties for the controls are set in this order:
- Properties are applied first from a stylesheet theme.
- Properties are then overridden based on properties set in the control.
- Properties are then overridden based on a customization theme.
Thus, the customization theme is guaranteed to have the final word in determining the look and feel of the control.
Skins themselves come in two flavors: default skins and explicitly named skins. Thus, you might create a Labels skin file with this declaration:
<asp:Label runat="server"
ForeColor="Blue" Font-Size="Large"
Font-Bold="True" Font-Italic="True" />
This is a default skin for all Label controls. It looks like the definition of anASP:Labelcontrol, but it is housed in a skin file and, thus, is used to define the look and feel of all Label objects within that skin file’s theme.
In addition, however, you might decide that some labels must be red. To accomplish this, create a second skin, but assign this skin aSkinIDproperty:
<asp:Label runat="server" SkinID="RedLabel"
ForeColor="Red" Font-Size="Large"
Font-Bold="True" Font-Italic="True" />
Any label that does not have aSkinIDattribute will get the default skin; any label that setsSkinID ="Red"will get your named skin.
The steps to providing a personalized web site are:
- Create the test site.
- Organize your themes and skins.
- Enable themes and skins for your site.
- Specify themes declaratively if you wish.
Please check back next week for the conclusion of this article.
| DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware. |
|
This article is excerpted from the book Programming Visual Basic 2005, written by Jesse Liberty (O'Reilly, 2005; ISBN: 0596009496). Check it out today at your favorite bookstore. Buy this book now.
|
|