O'Reilly logo

ASP.NET 2.0 Cookbook, 2nd Edition by Geoffrey T. LeBlond, Michael A Kittel

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

10.6. User-Personalized Themes

Problem

You want to provide to users of your application the ability to choose how the application looks.

Solution

Use the Profile features along with the Theme features in ASP.NET 2.0. Implement the profile features described in Recipe 10.1, modify web.config to add a property to store the selected theme in the profile, and set the selected theme in the Page_PreInit event handler of the pages in your application.

Modify web.config as follows:

  • Add an <add> element to the <properties> element to include the name of the user’s selected theme in the profile.

In the code-behind class for the pages in your application, use the .NET language of your choice as follows:

  • Implement the event handler for the Page_PreInit event to set the theme for the page from the user’s profile.

The solution we have implemented to demonstrate the solution is shown in Examples 10-19, 10-20, 10-21 through 10-22. Example 10-19 shows the modifications made to web.config. Example 10-20 shows the .aspx file used to enter the user profile data, and Examples 10-21 (VB) and 10-22 (C#) show the code-behind classes for the page used to enter the user profile data.

Discussion

In some cases, you’ll want to allow the user to choose the look and feel she wants for your application. The combination of the profile and theme features in ASP.NET 2.0 provides the ability to implement this functionality in your application with very little code.

For our example, we built on the solution provided in Recipe ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required