You can decorate the public properties of the web part class with the following attributes from System.ComponentModel so that your web part can runs in a stateless environment, like SharePoint:
- WebDisplayName - This string shows as the label for the control in the Editor pane.
- WebDescription - This string shows as a tooltip over the display name.
- WebBrowsable - When this Boolean is set to true, the end user will be able to see the property in the Editor pane. Set it to false to imperatively set the property’s value on behalf of the end user.
- Personalizable - This enum has two settings:
- PersonalizationScope.Shared indicates that SharePoint should only store one value for everyone.
- PersonalizationScope.User indicates that SharePoint should still store one common value for everyone, but allow anyone who has permission to personalize to change that value to whatever he or she would like it to be.
The following code example demonstrates how to use these attributes:
Each public property can have a unique set of attributes. SharePoint supports several different types:
- string - Rendered as a textbox
- bool - Rendered as a checkbox
- datetime - Rendered as a textbox
- int - Rendered as a numeric-only textbox
- float - Rendered as a numeric-only textbox
- knowncolor - Rendered as a drop-down list
- enum - Rendered as a drop-down list
The following figure depicts how SharePoint render different types of public properties:
Code sample as shown below: