Edit

Share via


WebPartChrome.GetWebPartVerbs(WebPart) Method

Definition

Gets a collection of verbs that should be rendered with a WebPart control.

protected:
 virtual System::Web::UI::WebControls::WebParts::WebPartVerbCollection ^ GetWebPartVerbs(System::Web::UI::WebControls::WebParts::WebPart ^ webPart);
protected virtual System.Web.UI.WebControls.WebParts.WebPartVerbCollection GetWebPartVerbs (System.Web.UI.WebControls.WebParts.WebPart webPart);
abstract member GetWebPartVerbs : System.Web.UI.WebControls.WebParts.WebPart -> System.Web.UI.WebControls.WebParts.WebPartVerbCollection
override this.GetWebPartVerbs : System.Web.UI.WebControls.WebParts.WebPart -> System.Web.UI.WebControls.WebParts.WebPartVerbCollection
Protected Overridable Function GetWebPartVerbs (webPart As WebPart) As WebPartVerbCollection

Parameters

webPart
WebPart

The control currently being rendered.

Returns

A WebPartVerbCollection containing all the verbs that should be rendered with webPart.

Exceptions

webPart is null.

Examples

The following code example demonstrates use of the GetWebPartVerbs method. For the full code required to run the example, see the Example section of the WebPartChrome class overview topic.

The following section from the code example demonstrates how to override the GetWebPartVerbs method. The overridden method uses the base method to retrieve all verbs from the webPart control, then iterates through the verb collection, adding all verbs except the close verb to an ArrayList object. This reduced set of verbs is then assigned to a new WebPartVerbCollection, which is returned to the caller.

protected override WebPartVerbCollection GetWebPartVerbs(WebPart webPart)
{
  ArrayList verbSet = new ArrayList();
  foreach (WebPartVerb verb in base.GetWebPartVerbs(webPart))
  {
    if (verb.Text != "Close")
      verbSet.Add(verb);
  }
  WebPartVerbCollection reducedVerbSet = 
    new WebPartVerbCollection(verbSet);
  return reducedVerbSet;
}
Protected Overrides Function GetWebPartVerbs _
  (ByVal webPart As WebPart) As WebPartVerbCollection

  Dim verbSet As New ArrayList()
  Dim verb As WebPartVerb
  For Each verb In MyBase.GetWebPartVerbs(webPart)
    If verb.Text <> "Close" Then
      verbSet.Add(verb)
    End If
  Next verb

  Dim reducedVerbSet As WebPartVerbCollection = _
    New WebPartVerbCollection(verbSet)

  Return reducedVerbSet
End Function

If you load the Web page in a browser and click the verbs menu (shown with a downward arrow in the title bar) of each WebPart control, you can see that the close verb is not rendered for any control.

Remarks

The GetWebPartVerbs method provides developers with an opportunity to override the method and exclude certain verbs from being rendered. This is similar to the FilterWebPartVerbs method, which also can exclude verbs from being rendered.

However, the GetWebPartVerbs method is not meant for cases where you want to check some criteria to decide whether to render a verb. Instead, this method is useful when you know in advance that you always want to exclude a certain verb. For example, if you develop a custom WebPartChrome class, you might decide that you always want to exclude the close verb on WebPart controls, so that users can never close the controls. Rather than setting the AllowClose property to false on all the controls, you can simply override the GetWebPartVerbs method and exclude close verbs from being rendered on any WebPart control rendered with your custom WebPartChrome object.

Applies to

See also