Home   |   QuickStart Welcome   |   ASP.NET   |   Web Services   |   How Do I...?   
  |   I want my samples in...      

ASP.NET 2.0 Quickstart Tutorials

Personalization and Web Parts

The Web Part Control Set includes a page personalization system that can save changes made by users until their next session. Personalized settings can include page layout, visible or invisible parts, and part properties. To mark a property as personalizable, you can mark the control property with the Personalizable attribute. Typically, a property should have both the WebBrowsable and Personalizable attributes, so it can be edited and saved.

This example shows a page with a web part that has a personalizable property.
  1. Log in to the page.
  2. Select "Edit" from the dropdown. The editor will now be visible, with a property grid showing the Text property.
  3. Change the ContentText value, and click OK.
  4. Close the browser, and then return to the page. The web part will continue to show the new text.
VB Per-User Personalization
Run Sample View Source

The Web Part Control Set also provides a second level of personalization for pages, called shared personalization. Using this mode, a user can create a customized view that is used as the default for all users viewing a page. Shared personalization does not alter the contents of the physical page; instead, it defines a set of customizations that are applied to the page before per-user personalization is applied.

To specify that a setting be modifiable in shared personalization, you can add the Personalizable(PersonalizationScope.Shared) attribute to the property. In this example, the MaxTextDisplayLength property of the TextDisplayWebPart is marked as being personalizable in shared mode. It also modifies the CreateEditorParts method to only return the custom editor part when in shared mode.

VB Shared Personalization
Run Sample View Source

The personalized settings of a page are saved permanently, but it may be useful to reset these settings back to their defaults. You can do this programmatically, using the PersonalizationAdministration class. To reset the per-user personalization of a page, call PersonalizationAdministration.ResetUserState, passing in the page path and the user name. To reset the shared personalization, call PersonalizationAdministration.ResetSharedState, passing in the page path.

  1. Log in to the page.
  2. select "Design" from the dropdown.
  3. Move Web Parts to different WebPartZones.
  4. Click the "Reset User State". The personalized information will be reset.


VB Resetting Personalization
Run Sample View Source