Welcome to Office Zealot Sign in | Join | Help
Adding a WebPart ToolPart

 A Summary of SharePoint WebPart ToolPart Types

WebPartToolPart

The WebPartToolPart is the default ToolPart for a SharePoint WebPart and is included in all WebParts.  It contains all the default properties of a WebPart, which can be seen by the end user through the WebPart property interface.  These properties include all the basic information for a WebPart’s appearance and layout within a SharePoint page. 

Default WebPart properties:

  • Appearance
    • Title
    • Width
    • Frame State
    • Frame Style
  • Layout
    • Visible on Page
    • Direction
    • Zone
    • Part Order
  • Advanced
    • Allow Minimize
    • Allow Close 
    • Allow Zone Change
    • Allow Export Sensitive Properties
    • Detail Link 
    • Description 
    • Help Link 
    • Icon File (Large) 
    • Icon File (Small) 
    • Missing Assembly Error 
    • Target Audiences

CustomPropertyToolPart

The CustomPropertyToolPart is an additional ToolPart that is added when custom properties are added to the WebPart programmatically.  A custom property is any WebPart property that is not a member of the base WebPart properties listed in the section above and is visible to the user through the WebPart properties interface.  Similar to the WebPartToolPart, properties can be grouped into sections.  All sections are part of a single CustomPropertyToolPart.

Examples of custom properties

  • Database connection information
  • Connectivity between WebParts
  • URLs
  • Information that can be used within the code of your WebPart

For more information on building WebParts with custom properties, see Creating a Web Part with Custom Properties.

A Custom ToolPart (built by the developer)

The third type of ToolPart is a custom ToolPart built by the developer.  Properties, layout, and functionality used by this ToolPart are built programmatically.  The Html and controls that are visible to the end user are created manually, allowing for much greater interaction and functionality than the other 2 static ToolParts.

For more information on creating custom ToolParts, see Creating a Web Part with a Custom Tool Part.

 

Adding ToolParts to the WebPart

All types of ToolParts become associated with a WebPart by adding them to the WebPart’s collection of ToolParts through the GetToolParts method.  This method overrides the base method of the WebPart class and is necessary only when adding custom ToolParts.  If only default and custom properties are used in a WebPart, they will be added automatically and the GetToolParts method is unnecessary.

GetToolParts() Method of WebPart

Public Overrides Function GetToolParts() As Microsoft.SharePoint.WebPartPages.ToolPart()
 ' Add the custom toolpart to the webpart's toolparts
        Dim toolParts(3) As ToolPart
        Dim objWebToolPart As WebPartToolPart = New WebPartToolPart
        Dim objCustomProperty As CustomPropertyToolPart = New CustomPropertyToolPart
        toolParts(0) = objWebToolPart
        toolParts(1) = objCustomProperty
        toolParts(2) = New YourCustomToolpart( )
        Return toolParts
End Function

This GetToolParts method adds the 3 different types of ToolParts to the WebPart’s ToolParts collection.  You can add multiple ToolParts to a WebPart in a similar manner.  ToolParts can remain hidden from view by not adding them to this collection.

Add the default WebPartToolPart to the collection:

Dim objWebToolPart As WebPartToolPart = New WebPartToolPart
toolParts(0) = objWebToolPart

Add a CustomPropertyToolPart to the collection:

Dim objCustomProperty As CustomPropertyToolPart = New CustomPropertyToolPart
toolParts(1) = objCustomProperty

Add a custom built ToolPart (YourCutomToolPart is the class name) to the collection:

toolParts(2) = New YourCustomToolPart( )
Posted: Monday, December 12, 2005 8:53 AM by rbedell

Comments

Daniel Sack said:

Develop webparts with custom tool parts in SharePoint 2007

# February 11, 2008 2:15 AM
Anonymous comments are disabled