Customizing the Property Task Pane
SharePoint generates the controls displayed in the web part properties pane based on the data type of the property and whether or not it is marked as WebBrowsable in the property attributes. Table 11-6 lists the controls generated for various data types.
Table 11-6. Default property pane control types
Type | Generated control |
|---|---|
String | Text box |
Numeric | Text box |
Date | Text box |
Boolean | Checkbox |
Array | Drop-down box |
Enumeration | Drop-down list box |
You can override that behavior by creating custom editor parts that render one or more controls in the properties pane.
To display a custom editor part in the web part properties task pane:
Create an
EditorPartclass that renders the editor to display.Override the web part's
CreateEditorPartsmethod to add the newEditorPartto theEditorPartCollection.
For example, the following class creates an editor part that displays a calendar in the properties pane:
// Create a custom EditorPart to edit the WebPart. class CalendarEditorPart : EditorPart { Calendar _cal; DateTime _date; // Get settings from web part. public override void SyncChanges( ) { Properties4 part = (Properties4)this.WebPartToEdit; _date = part.CalDate; } // Apply new settings to web part. public override bool ApplyChanges( ) { Properties4 part = (Properties4)this.WebPartToEdit; // Update the web part with the selected date. part.CalDate = this._cal.SelectedDate; return true; } // Render the control. protected override void CreateChildControls( ) { // Set the title to ...