Share via

CustomPropertyToolPart class

Represents the default tool part that is displayed in the tool pane for a Web Part that implements one or more custom properties (properties other than those provided by the WebPart base class).

Inheritance hierarchy


Namespace:  Microsoft.SharePoint.WebPartPages
Assembly:  Microsoft.SharePoint (in Microsoft.SharePoint.dll)


<AspNetHostingPermissionAttribute(SecurityAction.LinkDemand, Level := AspNetHostingPermissionLevel.Minimal)> _
Public NotInheritable Class CustomPropertyToolPart _
    Inherits ToolPart
Dim instance As CustomPropertyToolPart
[AspNetHostingPermissionAttribute(SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
public sealed class CustomPropertyToolPart : ToolPart


A custom property will be automatically displayed using an instance of the CustomPropertyToolPart class in the default property pane if the property is of type String, Boolean, Integer, or Enum. The following table describes how each of these property types is displayed in the CustomPropertyToolPart class in the property pane.

Property type

Displayed in property pane as


Check box


Drop down


Text box


Text box


Text box


The following simple Web Part example demonstrates the use of the WebPartToolPart class and the CustomPropertyToolPart class to customize the display of Web Part properties in the tool pane. The example overrides the GetToolParts method of the WebPart base class in order to display the Web Part's standard properties in the tool pane followed by its custom properties, and then to expand specific sections of each tool part and to hide specific standard properties. The WebPartToolPart class automatically displays the Web Part's standard properties, and the CustomPropertyToolPart class automatically displays the Web Part's custom properties.

Imports System
Imports System.ComponentModel
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Xml.Serialization
Imports Microsoft.SharePoint
Imports Microsoft.SharePoint.Utilities
Imports Microsoft.SharePoint.WebPartPages

' A simple Web Part with a single custom Text property.

<DefaultProperty("Text"), ToolboxData("<{0}:WebPart1 
XmlRoot(Namespace:="WebPartLibrary1")> _
 Public Class WebPart1 
Inherits Microsoft.SharePoint.WebPartPages.WebPart

    Private Const _defaultText As String = ""
    Dim _text As String = _defaultText

    ' The Web Part's single custom Text property.

    <Browsable(True), Category("Miscellaneous"), 
        DefaultValue(_defaultText), WebPartStorage(Storage.Personal), 
        FriendlyName("Text"), Description("Text Property")> _
    Property [Text]() As String
            Return _text
        End Get

        Set(ByVal Value As String)
            _text = Value
        End Set
    End Property

    ' An overridden version of the GetToolParts() method of the WebPart base class.
    ' The WebPartToolPart automatically displays the Web Part's standard properties
    ' The CustomPropertyToolPart displays automatically displays 
    '  the Web Part's custom properties

    Public Overrides Function GetToolParts() As ToolPart()
        Dim toolParts(2) As ToolPart
        Dim custom As CustomPropertyToolPart = New CustomPropertyToolPart
        Dim wptp As WebPartToolPart = New WebPartToolPart
        With wptp
        End With
        toolParts(0) = custom
        toolParts(1) = wptp
        Return toolParts
    End Function

    ' Renders the Web Part.

    Protected Overrides Sub RenderWebPart(ByVal output 
    As System.Web.UI.HtmlTextWriter)
    End Sub

End Class
using System;
using System.ComponentModel;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Xml.Serialization;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Utilities;
using Microsoft.SharePoint.WebPartPages;

namespace WebPartLibrary1CS
        ToolboxData("<{0}:WebPart1 runat=server></{0}:WebPart1>"),
    public class WebPart1 : Microsoft.SharePoint.WebPartPages.WebPart
        private const string defaultText = "";
        private string text=defaultText;

            FriendlyName("Text"),Description("Text Property")]
        public string Text
                return text;

                text = value;
        public override ToolPart[] GetToolParts()
            ToolPart[] toolparts = new ToolPart[2];
   CustomPropertyToolPart custom = new CustomPropertyToolPart();
            WebPartToolPart wptp = new WebPartToolPart();
            toolparts[0] = wptp;
            toolparts[1] = custom;

            return toolparts;
        protected override void RenderWebPart(HtmlTextWriter output)

Thread safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

See also


CustomPropertyToolPart members

Microsoft.SharePoint.WebPartPages namespace