Export (0) Print
Expand All

WebPart.Verbs Property

Gets a collection of custom verbs associated with a WebPart control.

Namespace: System.Web.UI.WebControls.WebParts
Assembly: System.Web (in system.web.dll)

public virtual WebPartVerbCollection Verbs { get; }
/** @property */
public WebPartVerbCollection get_Verbs ()

public function get Verbs () : WebPartVerbCollection

Not applicable.

Property Value

A WebPartVerbCollection that contains custom WebPartVerb objects associated with a WebPart control. The default value is Empty.

Verbs derive from the WebPartVerb class, and provide user interface (UI) actions that users can perform on a WebPart control. Usually verbs are represented in the UI as buttons, links, or menu items. By default, common Web Parts verbs appear on a drop-down verbs menu in each WebPart control's title bar. There are standard verbs for opening, closing, editing, and minimizing a control, and other verbs for exporting a definition for the control or loading a Help file. These verbs are not included in the Verbs collection, because the collection contains only custom verbs that you create and return by overriding this property in a derived class.

When you create custom verbs and add them to the Verbs collection, you can then access the verbs programmatically from a WebPart control.

Notes to Inheritors: Derived classes can override the Verbs property to allow users to add custom WebPartVerb objects to the verb collection for a WebPart control.

The following code example demonstrates how to access the Verbs property for a custom Web Parts control. This example assumes the use of a custom control, TextDisplayWebPart, created in the Example section of the WebPart class overview.

Note that for the code example to work, you must add a setting in the Web.config file to enable exporting Web Parts description files. Ensure that you have a Web.config file in the same directory as the Web page for this code example. Within the <system.web> section, make sure there is a <webParts> element with an enableExport attribute set to true, as in the following markup.

<webParts enableExport="true">

...

</webParts>

Load the Web page in a browser. When you click the Display Verb Count button, it accesses the Verbs property to get the count of custom verbs for the TextDisplayWebPart control, and displays the count in a label. Because no custom verbs have been added to the control in this case, the count is zero.

<%@ page language="C#" %>
<%@ register tagprefix="aspSample" 
             Namespace="Samples.AspNet.CS.Controls" 
             Assembly="TextDisplayWebPartCS"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">

void  button1_Click(object sender, EventArgs e)
{
  label1.Text = "Verb count = " + 
    textwebpart.Verbs.Count.ToString();
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
    <title>ASP.NET Example</title>
</head>
<body>
  <form id="Form1" runat="server">
    <asp:webpartmanager id="WebPartManager1" runat="server" />
    <asp:webpartzone
      id="WebPartZone1"
      runat="server"
      title="Zone 1"
      PartChromeType="TitleAndBorder">
        <parttitlestyle font-bold="true" ForeColor="#3300cc" />
        <partstyle
          borderwidth="1px"   
          borderstyle="Solid"  
          bordercolor="#81AAF2" />
        <zonetemplate>
          <aspSample:TextDisplayWebPart 
            runat="server"   
            id="textwebpart" 
            title = "Text Content WebPart" />        
        </zonetemplate>
    </asp:webpartzone>
    <asp:Button ID="button1" Runat="server" 
      OnClick="button1_Click" 
      Text="Display Verb Count" 
      />
    <asp:Label ID="label1" Runat="server" />
  </form>
</body>
</html>

<%@ page language="VJ#" %>
<%@ register tagprefix="aspSample" 
             Namespace="Samples.AspNet.JSL.Controls" 
             Assembly="TextDisplayWebPartJSL"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">

    void  Button1_Click(Object sender, EventArgs e)
    {
        label1.set_Text(System.Convert.ToString("Verb count = " 
            + textwebpart.get_Verbs().get_Count()));
    } //Button1_Click
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
    <title>ASP.NET Example</title>
</head>
<body>
  <form id="Form1" runat="server">
    <asp:webpartmanager id="WebPartManager1" runat="server" />
    <asp:webpartzone
      id="WebPartZone1"
      runat="server"
      title="Zone 1"
      PartChromeType="TitleAndBorder">
        <parttitlestyle font-bold="true" ForeColor="#3300cc" />
        <partstyle
          borderwidth="1px"   
          borderstyle="Solid"  
          bordercolor="#81AAF2" />
        <zonetemplate>
          <aspSample:TextDisplayWebPart 
            runat="server"   
            id="textwebpart" 
            title = "Text Content WebPart" />        
        </zonetemplate>
    </asp:webpartzone>
    <asp:Button ID="button1" Runat="server" 
      OnClick="Button1_Click" 
      Text="Display Verb Count" 
      />
    <asp:Label ID="label1" Runat="server" />
  </form>
</body>
</html>

Windows 98, Windows Server 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0

Community Additions

ADD
Show:
© 2014 Microsoft