|
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.
- Log in to the page.
- Select "Edit" from the dropdown.
- 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.
- Change the ContentText value, and click OK.
- Close the browser, and then return to the page. The web part will continue to show the new text.
C# Per-User Personalization
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.
- Log in to the page.
- Click on the Shared radio button.
- Click on the down arrow to the right of the TextDisplayWebPart title and select "Edit". The Text Editor will now be visible.
- Change the Text Length value, and click OK.
- Close the browser, and then return to the page. The web part will continue to show the new text.
C# Shared Personalization
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.
- Log in to the page.
- Select "Design" from the dropdown.
- Move Web Parts to different WebPartZones.
- Click the "Reset User State". The personalized information will be reset.
C# Resetting Personalization
|