Documente Academic
Documente Profesional
Documente Cultură
In this third part of a four-part series covering personalization with Visual Basic 2005, we'll learn
about anonymous personalization, themes and skins, and more. This article is excerpted from
chapter 12 of the book Programming Visual Basic 2005, written by Jesse Liberty (O'Reilly,
2005; ISBN: 0596009496).
Personalize with Complex Types
To make a useful commercial site, you often have to store complex user-defined
types (classes) or collections.
In the next exercise, you’ll edit the Web.config file to add a collection of strings
called CHOSENBOOKS. Doing so will allow the user to choose one or more
books, and have those choices stored in the user’s profile.
Add a line to Web.config for your new property:
<profile>
<properties>
<add name="lastName" />
<add name="firstName" />
<add name="phoneNumber" />
<add name="birthDate" type="System.DateTime"/>
<add name="CHOSENBOOKS"
type="System.Collections. Specialized.StringCollection" />
</properties>
</profile>
To see this collection at work, edit the page ProfileInfo.aspx, inserting a row with a
CheckBoxList just above the row with the Save button, as shown in Figure 12-37.
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:
1. Create the test site.
2. Organize your themes and skins.
3. Enable themes and skins for your site.
4. Specify themes declaratively if you wish.
Please check back next week for the conclusion of this article.