Web Parts verbs are interactive UI elements, typically represented by buttons or hyperlinks, that appear in pages that use Web Parts controls. Users click verbs to carry out common UI actions for Web Parts controls, such as closing a WebPart control or closing the edit display mode (a special page view associated with the EditorZone control). All standard verbs provided with the Web Parts control set are associated with either a Web Parts zone (WebPartZone, EditorZone, CatalogZone, or ConnectionsZone) or a Web Parts Part control (WebPart, GenericWebPart, EditorPart, or CatalogPart).

When the standard verbs are associated with a zone, their actions apply at the zone level, and the verbs usually appear in the zone's header or footer area. The following table lists the common zone-level verbs and describes their actions.

Zone-level verb

Action

Close verb

Used with zones that inherit from the ToolZone class. Hides the UI for a zone and typically returns the page to its normal browse mode view.

Apply verb

Used with zones that inherit from the EditorZoneBase class. Applies changes that a user has made.

OK verb

Used with zones that inherit from the EditorZoneBase class. Has the combined effect of the apply and close verbs; it applies changes and hides the zone's UI.

Cancel verb

Used with zones that inherit from the ToolZone class. Cancels any pending changes a user has made.

Add verb

Used with zones that inherit from the CatalogZoneBase class. Adds a control that a user has selected from a catalog of controls to a specified WebPartZone zone.

Configure verb

Used with zones that inherit from the ConnectionsZone class. Opens a view to enable users to configure existing connections.

Disconnect verb

Used with zones that inherit from the ConnectionsZone class. Terminates an existing connection between two controls.

As for the standard verbs that are associated with Part controls, their actions apply to the control itself (or to its child controls). The part control acts as a container for the verb and manages the rendering of the verb. Most standard verbs associated with part controls appear either directly in the title bar or in a drop-down verbs menu within the title bar. Whether these verbs appear directly in the header or in a verbs menu is determined by the WebPartVerbRenderMode property; by default, the verbs appear in a verbs menu. The following table lists common verbs associated with the various Part controls and describes their actions.

Part control verb

Action

Minimize verb

Appears in the verbs menu of each server control contained in a WebPartZoneBase zone. Reduces the control to a minimal representation, hiding everything in its UI except the restore verb.

Restore verb

Appears in the verbs menu of each server control contained in a WebPartZoneBase zone. Returns a minimized control to its normal size and view.

Close verb

Appears in the verbs menu of each server control contained in a WebPartZoneBase zone. Closes a control and adds it to the page catalog, which means the control is removed from the page but, if there is a properly designed catalog, users can reopen the closed control and return it to the page.

Connect verb

Appears in the verbs menu of a control contained in a WebPartZoneBase zone, if the page is in connect display mode and if the control can form connections. Opens a connection UI so that users can create a connection between controls.

Delete verb

Appears in the verbs menu of a control contained in a WebPartZoneBase zone, if the control was added to the page programmatically (rather than being declared in persistence format). Permanently deletes the control instance and any associated personalization data so that, unlike a closed control, the deleted instance can never be restored to the page.

Edit verb

Appears in the verbs menu of a control contained in a WebPartZoneBase zone, if the page is designed to permit editing of controls and if the page is in edit display mode. Selects the control for editing and opens the editing UI.

Export verb

Appears in the verbs menu of a control contained in a WebPartZoneBase zone, if the control and application are enabled for export. Opens a dialog box that enables users to export a description file that contains the serialized state of the control. For details, see the ExportMode property.

Help verb

Appears in the verbs menu of a control contained in a WebPartZoneBase zone, if the control is designed to provide a Help file. Launches a page that provides help for the control.

Along with the standard verbs that are provided with the Web Parts control set, you can also create custom verbs. A common scenario for creating custom verbs is to create verbs associated with Part controls. When you create these verbs, by default they will appear on the verbs menu along with the standard verbs. The basic approach for creating such verbs is to inherit from the WebPartVerb class to create one or more custom verbs. Then create a control that inherits from the WebPart base class and add the custom WebPartVerb objects to a WebPartVerbCollection collection. This collection can then be added to the Verbs collection of the control, which will cause the custom verbs to appear automatically on the control's verbs menu at run time. As with the standard verbs, you can access the custom verbs programmatically on a WebPart control.

Web Parts applications can use server controls that do not inherit from the WebPart class, such as custom controls, user controls, or ASP.NET controls. These server controls, if added to a WebPartZoneBase zone, are dynamically wrapped with a GenericWebPart object at run time, which enables them to function as run-time WebPart controls. To add custom verbs to a server control that does not inherit from the WebPart class, the server control must implement the IWebActionable interface and override its Verbs property.

When you create a verb, you can create two types of associated event handlers that will run when a user clicks the verb: a server-side event handler (code that runs on the server), and a client-side event handler (code that runs in the client browser). Also, you can define custom states for verbs, which is a useful way to provide visual cues to users. For example, you could create a state indicating that a verb has been selected, and then provide appropriate changes in the UI to notify the user that the verb is already selected. Another useful behavior is the ability to disable verbs; by doing this, you can prevent users from clicking verbs if doing so would be harmful or ineffective based on the state of the application.

The WebPartVerb class does not expose any unique methods; its exposed methods are all overrides of base methods. It does however contain a number of properties for developers to be aware of. The Checked property indicates whether a verb is currently selected. The ClientClickHandler and ServerClickHandler properties refer to the respective handlers within the class (if any exist) for client and server click events. The Description property contains text that describes the purpose of a verb in a ToolTip when users position a mouse pointer over the verb in the UI. The Enabled property indicates the current status of a verb, which determines whether a user can click the verb and execute its action. The ID property provides a unique ID for the verb object. The ImageUrl property contains a URL to an image that can be used to represent a verb in the UI in place of the default rendering (typically a button or a hyperlink). The Text property contains the label text that appears directly on the verb in the UI. The overridden Visible property determines whether a verb is currently displayed in the UI. Verbs are often hidden or disabled at different times in a Web Parts application; for example, specialty verbs (such as the edit verb and the connect verb) are displayed only when the appropriate controls, settings, and display modes exist on the page to enable those verbs to take meaningful action.

The following code example shows how to create a custom WebPartVerb object, and a custom zone that uses the OnCreateVerbs method to add the verb to the verbs menu of each WebPart control contained in the zone. There are four parts to the code example:

A source file that contains a simple custom WebPart control that displays some text.

A source file that contains a custom WebPartVerb object, and a simple custom WebPartZoneBase zone that overrides the OnCreateVerbs method to add the custom verb to WebPart controls in the zone.

A Web page that contains the custom zone and the custom WebPart control.

An explanation of how the example works.

The first part of the code example contains source code that creates a simple WebPart control that displays some text. For the code example to run, you must compile this source code. You can compile it explicitly and put the resulting assembly in your Web site's Bin folder or the global assembly cache. Alternatively, you can put the source code in your site's App_Code folder, where it will be dynamically compiled at run time. This code example uses the dynamic compilation approach. For a walkthrough that demonstrates how to compile, see Walkthrough: Developing and Using a Custom Web Server Control.

The second part of the example contains source code to create the custom zone and the custom WebPartVerb object. Note that the zone overrides the OnCreateVerbs method to add the custom verb to any WebPart controls in the zone. The verb is added by default to the verbs menu of the controls. Note that, in the code for the custom verb, the constructor for the verb uses a server click handler, and that the method called creates a complete copy of any control that inherits directly from the WebPart class, adding the newly created copy to the same zone. Like the first part of the code example, this source code must be compiled, and in this example the source file was placed in an App_Code subfolder to be dynamically compiled.

The third part of the code example is the Web page that hosts the controls. Note that there is a Register directive near the top of the page to declare the namespace of the custom controls. No assembly is declared because this example uses dynamic compilation. The custom WebPart control is declared within the custom zone. You could also declare other WebPart controls in this zone, and the custom verb would be added to their verbs menus as well.