
Step 3: Add a user-customizable Web Part property
After configuring the new class to act as a Web Part, add a customizable property for the Web Part.
The Web Part property determines the text that is rendered inside the Web Part. This is customized on the basis of the individual user.
For Web Parts based on the ASP.NET Web Parts Pages base class, the tags that are used for the customizable properties are named differently than Web Parts that are based on the Microsoft.SharePoint.WebPartPages.WebPart base class. The following list describes each of those properties:
-
The WebBrowsableAttribute class attribute ensures that your custom property renders in the editing tool pane in Windows SharePoint Services.
-
The WebDescriptionAttribute class attribute displays a tooltip to help guide users when editing your custom property.
-
The WebDisplayNameAttribute class attribute shows a display name for your custom property.
-
The PersonalizableAttribute class attribute determines if changes to your custom property affects all users or on a per-user basis.
To create the Web Part property
-
In the DisplayMessageWebPart file, copy and paste the following code to create a basic customizable property.
private string customMessage = “Hello, world!”;
public string DisplayMessage
{
get { return customMessage; }
set { customMessage = value; }
}
Private customMessage As String = “Hello, world!”
Public Property DisplayMessage() as String
Get
Return customMessage
End Get
Set(ByVal value as String)
customMessage = value
End Set
End Property
-
Then, add the following tags above the public declaration to allow changes on a per-user basis:
[WebBrowsable(true),
WebDescription("Displays a custom message"),
WebDisplayName("Display Message"),
Personalizable(PersonalizationScope.User)]
<WebBrowsable(True), _
WebDescription("Displays a custom message"), _
WebDisplayName("Display Message"), _
Personalizable(PersonalizationScope.User)> _
-
Now you have created a customizable Web Part property.