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

System.Object
  System.Web.UI.Control
    System.Web.UI.WebControls.WebControl
      System.Web.UI.WebControls.Panel
        System.Web.UI.WebControls.WebParts.Part
          System.Web.UI.WebControls.WebParts.EditorPart
            Microsoft.SharePoint.WebPartPages.EditorPartAdapter
              Microsoft.SharePoint.WebPartPages.ToolPart
                Microsoft.SharePoint.WebPartPages.CustomPropertyToolPart

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

Syntax

[AspNetHostingPermissionAttribute(SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
public sealed class CustomPropertyToolPart : ToolPart

Remarks

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

Boolean

Check box

Enum

Drop down

Integer

Text box

String

Text box

DateTime

Text box

Examples

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.

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
{
    [DefaultProperty("Text"),
        ToolboxData("<{0}:WebPart1 runat=server></{0}:WebPart1>"),
        XmlRoot(Namespace="WebPartLibrary1CS")]
    public class WebPart1 : Microsoft.SharePoint.WebPartPages.WebPart
    {
        private const string defaultText = "";
        private string text=defaultText;

        [Browsable(true),Category("Miscellaneous"),
            DefaultValue(defaultText),
            WebPartStorage(Storage.Personal),
            FriendlyName("Text"),Description("Text Property")]
        public string Text
        {
            get
            {
                return text;
            }

            set
            {
                text = value;
            }
        }
        
        public override ToolPart[] GetToolParts()
        {
            ToolPart[] toolparts = new ToolPart[2];
   CustomPropertyToolPart custom = new CustomPropertyToolPart();
            WebPartToolPart wptp = new WebPartToolPart();
            wptp.Expand(WebPartToolPart.Categories.Appearance);
            wptp.Hide(WebPartToolPart.Properties.FrameState);
            wptp.Hide(WebPartToolPart.Properties.FrameType);
            toolparts[0] = wptp;
            toolparts[1] = custom;

            return toolparts;
        }
        
        protected override void RenderWebPart(HtmlTextWriter output)
        {
            output.Write(SPEncode.HtmlEncode(Text));
        }
    }
}

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

Reference

CustomPropertyToolPart members

Microsoft.SharePoint.WebPartPages namespace