Page view counter

These tutorials demonstrate selected features in ASP.NET version 2.0, but they are compatible with later versions of ASP.NET as well. For the current documentation, see the ASP.NET portal on the MSDN Web site.

 

 

   Welcome   |   ASP.NET   |   Web Services   |   Class Browser   
  |   I want my samples in...      

ASP.NET 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.
  3. Click on the down arrow to the right of the TextDisplayWebPart title and select "Edit". The editor will now be visible, with a property grid showing the ContentText property.
  4. Change the ContentText value, and click OK.
  5. 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.

  1. Log in to the page.
  2. Click on the Shared radio button.
  3. Click on the down arrow to the right of the TextDisplayWebPart title and select "Edit". The Text Editor will now be visible.
  4. Change the Text Length value, and click OK.
  5. Close the browser, and then return to the page. The web part will continue to show the new text.


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