|
Themes and Profiles
You may want the end-users of your application to be able to choose and apply Themes dynamically.
By storing the active Theme in a
User Profile,
you can dynamically apply a theme based on user
preferences. To do this, you apply the Theme programmatically in code instead of setting the
Theme declaratively using the @Page directive or Web.config.
Assigning a Theme in Code
To apply a Theme from code, you set the Theme property of the Page object at runtime.
A Theme must be applied to a page very early in the request lifecycle, in the PreInit
event. The example below shows a Theme dynamically applied in this event when the user selects
a Theme name from a DropDownList control.
C# Assigning a Theme in Code
Using the Profile feature in ASP.NET 2.0, you can store a user's preference for a Theme and restore
it when the user logs in to your site. The example below demonstrates this technique. The user
can select their favorite color preference and save it to their profile, and then the page sets
the Theme based on this color preference by retrieving the Theme name from the Profile object.
Notice that if you log out of the site, the Theme is restored to the default (no theme), but if you
log back into the site, the user preference is retained.
C# Assigning a Theme Based on User Profile
|