Exam 70-553 - Customize a Web page by using themes and user profiles.

Section 2

  • Part 5
    • Topic 2

Customize a Web page by using themes and user profiles.

  • Apply a theme declaratively.
  • Apply a theme programmatically.
  • Apply a user-selected theme programmatically.
  • Define custom themes.
  • Define the appearance of a control by using skins.
  • Enable users to personalize an application by using Web Parts.
  • Track and store user-specific information by using user profiles.
  • Personalize a Web page by dynamically adding or removing child controls in a Placeholder control at run time.

Summary

ASP.Net themes are new to ASP.Net 2.0 and allow you to define the default appearance of server controls.

To Apply a theme declaratively you can specify the them in the applications web.config or specify it in the page directive for a particular page.

To Apply themes programmatically you can alter the Page’s theme property, but you must do so during the PreInit event.

To Define your own themes you must add a theme folder to your application and then add a folder for each theme you want to create. In each folder add a css file and add a skin file that defines the default look and feel for each server control. Below is an example of an entry in a skin file as taken from msdn:

<asp:Button runat="server"
BackColor="Red"
ForeColor="White"
Font-Name="Arial"
Font-Size="9px" />

You can enable users to personalize an application by leveraging Web Parts. Using web parts you use a Web Part Manager to control the Web Parts and Personalization process. On each page you define Web Part Zones that specify where the web parts will appear. You can use a Catalog Component to define what web parts are available. Users can then easily customize their pages.

Using ASP.Net 2.0 you can enable personalization. This enables user specific properties to be stored in a database or other source as configured through the personalization provider. In the Web Config you can define the properties that you want to keep track of and ASP.Net will automatically handle the storage of this data. Below is an example of defining three properties in an applications web config that will be stored through the personalization provider. (Example from MSDN)

<profile>
<properties>
<add name="BackColor" type="string" />
<add name="ForeColor" type="string" />
<add name="Links"
type="System.Collections.Specialized.StringCollection"
serializeAs="Xml" />
</properties>
</ profile>

Notice that you can specify the type. This enables you to use custom types for any property you want. Whats even better is that you can access the properties using intellisense as in the following example (also from msdn.

If Profile.Links.Count = 0 Then
  Profile.Links.Add("http://www.contoso.com")
  Profile.Links.Add("http://www.northwind.com")
End If

You can dynamically add controls to a placeholder control at runtime by creating a new instance of the control either directly or through the LoadControl method of the page class and then passing in the reference to the Placeholders AddControl method.

Other Resources & Links:

ASP.Net Themes and Styles
http://msdn2.microsoft.com/en-us/library/wcyt4fxb.aspx

How To: Apply ASP.Net Themes
http://msdn2.microsoft.com/en-us/library/0yy5hxdk.aspx

How To: Define ASP.Net Page Themes
http://msdn2.microsoft.com/en-us/library/ms247256(VS.80).aspx

Personalize Your Portal with User Controls and Custom Web Parts
http://msdn.microsoft.com/msdnmag/issues/05/09/WebParts/

Personalization and User Profiles in ASP.Net 2.0
http://msdn.microsoft.com/msdnmag/issues/05/10/CuttingEdge/default.aspx

Enterprise Library Memory Issues

Exam 70-553 - Implement a consistent page design by using master pages.