WebPartVerb 类

定义

提供使用户能在 Web 部件页面上执行操作的交互式用户界面 (UI) 元素。Provides an interactive user interface (UI) element that enables users to perform actions on a Web Parts page.

public ref class WebPartVerb : System::Web::UI::IStateManager
[System.ComponentModel.TypeConverter(typeof(System.Web.UI.WebControls.EmptyStringExpandableObjectConverter))]
public class WebPartVerb : System.Web.UI.IStateManager
[<System.ComponentModel.TypeConverter(typeof(System.Web.UI.WebControls.EmptyStringExpandableObjectConverter))>]
type WebPartVerb = class
    interface IStateManager
Public Class WebPartVerb
Implements IStateManager
继承
WebPartVerb
属性
实现

示例

下面的代码示例演示如何创建自定义 WebPartVerb 对象,以及使用 OnCreateVerbs 方法将谓词添加到区域中包含的每个控件的谓词菜单的自定义区域 WebPartThe 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:

  • 一个源文件,其中包含一个简单的自定义 WebPart 控件,用于显示某些文本。A source file that contains a simple custom WebPart control that displays some text.

  • 一个包含自定义对象的源文件 WebPartVerb ,以及一个简单的自定义 WebPartZoneBase 区域,它重写 OnCreateVerbs 方法以将自定义谓词添加到 WebPart 区域中的控件。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.

  • 包含自定义区域和自定义控件的网页 WebPartA Web page that contains the custom zone and the custom WebPart control.

  • 此示例的工作原理的说明。An explanation of how the example works.

此代码示例的第一部分包含创建 WebPart 显示某些文本的简单控件的源代码。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. 可以显式编译该程序集,并将生成的程序集放在网站的 Bin 文件夹或全局程序集缓存中。You can compile it explicitly and put the resulting assembly in your Web site's Bin folder or the global assembly cache. 或者,您可以将源代码放在站点的 App_Code 文件夹中,它将在运行时动态编译。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. 有关演示如何编译的演练,请参阅 演练:开发和使用自定义 Web 服务器控件For a walkthrough that demonstrates how to compile, see Walkthrough: Developing and Using a Custom Web Server Control.

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Security.Permissions;
using System.Collections.Generic;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

namespace Samples.AspNet.CS.Controls
{

    // This code snippet creates a simple Web Part control.
    [AspNetHostingPermission(SecurityAction.Demand,
      Level = AspNetHostingPermissionLevel.Minimal)]
    [AspNetHostingPermission(SecurityAction.InheritanceDemand,
      Level = AspNetHostingPermissionLevel.Minimal)]
    public class SimpleControl : WebPart
    {

        private String _text = "Simple control text";

        public string Text
        {
            get
            {
                if (_text != null)
                    return _text;
                else
                    return string.Empty;
            }
            set { _text = value; }
        }

        protected override void Render(System.Web.UI.HtmlTextWriter 
      writer)
        {
            writer.Write(this.Text);
        }
    }
}
Imports System.Data
Imports System.Configuration
Imports System.Web
Imports System.Web.Security
Imports System.Collections.Generic
Imports System.Security.Permissions
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.WebControls.WebParts
Imports System.Web.UI.HtmlControls

' This code snippet creates a simple Web Part control.
Namespace Samples.AspNet.VB.Controls

  <AspNetHostingPermission(SecurityAction.Demand, _
    Level:=AspNetHostingPermissionLevel.Minimal)> _
  <AspNetHostingPermission(SecurityAction.InheritanceDemand, _
    Level:=AspNetHostingPermissionLevel.Minimal)> _
  Public Class SimpleControl
    Inherits System.Web.UI.WebControls.WebParts.WebPart

    Private _text As String = "Simple control text"

    Public Property [Text]() As String
      Get
        If Not (_text Is Nothing) Then
          Return _text
        Else
          Return String.Empty
        End If
      End Get
      Set(ByVal value As String)
        _text = value
      End Set
    End Property

    Protected Overrides Sub Render(ByVal writer _
      As System.Web.UI.HtmlTextWriter)

      writer.Write(Me.Text)

    End Sub

  End Class

End Namespace

该示例的第二部分包含用于创建自定义区域和自定义对象的源代码 WebPartVerbThe second part of the example contains source code to create the custom zone and the custom WebPartVerb object. 请注意,区域将重写 OnCreateVerbs 方法,以将自定义谓词添加到 WebPart 区域中的任何控件。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. 请注意,在自定义谓词的代码中,谓词的构造函数使用服务器单击处理程序,并且调用的方法会创建直接从类继承的任何控件的完整副本,并 WebPart 将新创建的副本添加到相同区域。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. 与代码示例的第一部分一样,此源代码必须编译,在此示例中,源文件被放入要动态编译的 App_Code 子文件夹中。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.

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Security.Permissions;
using System.Collections.Generic;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

namespace Samples.AspNet.CS.Controls
{
/* 
This code sample creates a Web Part zone and adds the 
"Copy Web Part" verb to any control in the zone.
*/
[AspNetHostingPermission(SecurityAction.Demand,
    Level = AspNetHostingPermissionLevel.Minimal)]
[AspNetHostingPermission(SecurityAction.InheritanceDemand,
    Level = AspNetHostingPermissionLevel.Minimal)]
public class ZoneWithAddedVerb : WebPartZone
{

  protected override void OnCreateVerbs(WebPartVerbsEventArgs e)
  {
    List<WebPartVerb> newVerbs = new List<WebPartVerb>();
    newVerbs.Add(new CopyWebPartVerb(CopyWebPartToNewOne));
    e.Verbs = new WebPartVerbCollection(e.Verbs,newVerbs);
    base.OnCreateVerbs(e);
  }

  void CopyWebPartToNewOne(object sender, WebPartEventArgs e)
  {
    WebPartManager wpmgr = 
      WebPartManager.GetCurrentWebPartManager(Page);
    System.Web.UI.WebControls.WebParts.WebPart wp;
    Type tp = e.WebPart.GetType(); 
    wp = (System.Web.UI.WebControls.WebParts.WebPart)Activator.CreateInstance(tp);   
    wpmgr.AddWebPart(wp, e.WebPart.Zone, e.WebPart.ZoneIndex + 1);
  }
}
  [AspNetHostingPermission(SecurityAction.Demand,
    Level = AspNetHostingPermissionLevel.Minimal)]
  [AspNetHostingPermission(SecurityAction.InheritanceDemand,
    Level = AspNetHostingPermissionLevel.Minimal)]
  internal class CopyWebPartVerb : WebPartVerb
  {
    private const String _copyWebPartImageUrl = "~/CopyVerb.ico";

    internal CopyWebPartVerb(WebPartEventHandler serverClickHandler) :  
       base("MyVerb", serverClickHandler)
    { }
    public override string Text
    {
      get { return "Copy Web Part"; }
      set { ;}
    }
    public override string Description
    {
      get { return "This verb will copy this web part control " +
        "to a new one below"; }
      set { ; }
    }
    public override bool Enabled
    {
      get { return base.Enabled; }
      set { base.Enabled = value; }
    }
    
    public override string ImageUrl
    {
      get { return _copyWebPartImageUrl; }
      set { ; }
    }
  }
}
Imports System.Data
Imports System.Configuration
Imports System.Web
Imports System.Web.Security
Imports System.Security.Permissions
Imports System.Collections.Generic
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.WebControls.WebParts
Imports System.Web.UI.HtmlControls

' This code sample creates a Web Part zone and adds the 
' "Copy Web Part" verb to any control in the zone.
Namespace Samples.AspNet.VB.Controls

  <AspNetHostingPermission(SecurityAction.Demand, _
    Level:=AspNetHostingPermissionLevel.Minimal)> _
  <AspNetHostingPermission(SecurityAction.InheritanceDemand, _
    Level:=AspNetHostingPermissionLevel.Minimal)> _
  Public Class ZoneWithAddedVerb
    Inherits WebPartZone

    'public class ExtendedWebPartZoneBase 
    Protected Overrides Sub OnCreateVerbs(ByVal e _
      As WebPartVerbsEventArgs)

      Dim newVerbs As List(Of WebPartVerb) = _
        New List(Of WebPartVerb)
      newVerbs.Add(New CopyWebPartVerb(AddressOf CopyWebPartToNewOne))
      e.Verbs = New WebPartVerbCollection(e.Verbs, newVerbs)
      MyBase.OnCreateVerbs(e)

    End Sub


    Sub CopyWebPartToNewOne(ByVal sender As Object, _
      ByVal e As WebPartEventArgs)

      Dim wpmgr As WebPartManager = _
        WebPartManager.GetCurrentWebPartManager(Page)
      Dim wp As System.Web.UI.WebControls.WebParts.WebPart
      Dim tp As Type = e.WebPart.GetType()
      wp = CType(Activator.CreateInstance(tp), _
        System.Web.UI.WebControls.WebParts.WebPart)
      wpmgr.AddWebPart(wp, e.WebPart.Zone, e.WebPart.ZoneIndex + 1)

    End Sub

  End Class


  <AspNetHostingPermission(SecurityAction.Demand, _
    Level:=AspNetHostingPermissionLevel.Minimal)> _
  <AspNetHostingPermission(SecurityAction.InheritanceDemand, _
    Level:=AspNetHostingPermissionLevel.Minimal)> _
  Friend Class CopyWebPartVerb
    Inherits WebPartVerb
    Private Const _copyWebPartImageUrl As String = "~/CopyVerb.ico"

    Friend Sub New(ByVal serverClickHandler As WebPartEventHandler)
      MyBase.New("MyVerb", serverClickHandler)

    End Sub

    Public Overrides Property [Text]() As String
      Get
        Return "Copy Web Part"
      End Get
      Set(ByVal value As String)
      End Set
    End Property

    Public Overrides Property Description() As String
      Get
        Return "This verb will copy this web part control to a " _
               & "new one below"
      End Get
      Set(ByVal value As String)
      End Set
    End Property

    Public Overrides Property Enabled() As Boolean
      Get
        Return MyBase.Enabled
      End Get
      Set(ByVal value As Boolean)
        MyBase.Enabled = value
      End Set
    End Property
    
    Public Overrides Property ImageUrl() As String
      Get
        Return Me._copyWebPartImageUrl
      End Get
      Set(ByVal value As String)
      End Set
    End Property

  End Class

End Namespace

此代码示例的第三部分是承载控件的网页。The third part of the code example is the Web page that hosts the controls. 请注意, Register 页面顶部附近有一个指令,用于声明自定义控件的命名空间。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. 自定义 WebPart 控件在自定义区域中声明。The custom WebPart control is declared within the custom zone. 您还可以 WebPart 在此区域中声明其他控件,并将自定义谓词添加到其谓词菜单中。You could also declare other WebPart controls in this zone, and the custom verb would be added to their verbs menus as well.

<%@ Page Language="C#" %>
<%@ Register TagPrefix="verbsample" 
    namespace="Samples.AspNet.CS.Controls" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <asp:WebPartManager ID="WebPartManager1" runat="server" />
    <verbsample:ZoneWithAddedVerb id="ZoneWithAddedVerb1" 
      HeaderText="Zone with Added Verb" runat="server">
        <ZoneTemplate>
           <verbsample:SimpleControl id="SimpleControl1" 
            title="Simple Control" runat="server" /> 
        </ZoneTemplate>
        </verbsample:ZoneWithAddedVerb>
     </form>
</body>
</html>
<%@ Page Language="VB" %>
<%@ Register TagPrefix="verbsample" 
    namespace="Samples.AspNet.VB.Controls" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <asp:WebPartManager ID="WebPartManager1" runat="server" />
    <verbsample:ZoneWithAddedVerb id="ZoneWithAddedVerb1" 
      HeaderText="Zone with Added Verb" runat="server">
        <ZoneTemplate>
           <verbsample:SimpleControl id="SimpleControl1" 
            title="Simple Control" runat="server" /> 
        </ZoneTemplate>
        </verbsample:ZoneWithAddedVerb>
     </form>
</body>
</html>

在浏览器中加载页面,然后单击自定义控件上的谓词菜单 WebPartLoad the page in a browser, and click the verbs menu on the custom WebPart control. 复制 Web 部件 谓词应可见。The Copy Web Part verb should be visible. 单击该谓词,并注意该控件的副本将添加到该区域中。Click the verb, and note that a copy of the control is added to the zone.

注解

Web 部件谓词是交互式 UI 元素,通常由按钮或超链接表示,它们显示在使用 Web 部件控件的页面中。Web Parts verbs are interactive UI elements, typically represented by buttons or hyperlinks, that appear in pages that use Web Parts controls. 用户单击谓词以执行 Web 部件控件的常见 UI 操作,例如关闭 WebPart 控件或关闭编辑显示模式 (与控件) 关联的特殊页面视图 EditorZoneUsers 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). Web 部件控制集提供的所有标准谓词都与 Web 部件区域 (WebPartZoneEditorZoneCatalogZoneConnectionsZone) 或 Web 部件 Part WebPartGenericWebPartEditorPart 或 (的) 控件 CatalogPart 相关联。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 与从类继承的区域一起使用 ToolZoneUsed with zones that inherit from the ToolZone class. 隐藏区域的 UI,并且通常会将页面返回到它的正常浏览模式视图。Hides the UI for a zone and typically returns the page to its normal browse mode view.
应用谓词Apply verb 与从类继承的区域一起使用 EditorZoneBaseUsed with zones that inherit from the EditorZoneBase class. 应用用户已进行的更改。Applies changes that a user has made.
确定谓词OK verb 与从类继承的区域一起使用 EditorZoneBaseUsed with zones that inherit from the EditorZoneBase class. 具有应用和关闭谓词的组合效果;它应用更改并隐藏区域的 UI。Has the combined effect of the apply and close verbs; it applies changes and hides the zone's UI.
取消谓词Cancel verb 与从类继承的区域一起使用 ToolZoneUsed with zones that inherit from the ToolZone class. 取消用户所做的任何挂起的更改。Cancels any pending changes a user has made.
添加谓词Add verb 与从类继承的区域一起使用 CatalogZoneBaseUsed with zones that inherit from the CatalogZoneBase class. 将用户从控件目录中选择的控件添加到指定 WebPartZone 区域。Adds a control that a user has selected from a catalog of controls to a specified WebPartZone zone.
配置谓词Configure verb 与从类继承的区域一起使用 ConnectionsZoneUsed with zones that inherit from the ConnectionsZone class. 打开一个视图,使用户能够配置现有连接。Opens a view to enable users to configure existing connections.
断开连接谓词Disconnect verb 与从类继承的区域一起使用 ConnectionsZoneUsed with zones that inherit from the ConnectionsZone class. 终止两个控件之间的现有连接。Terminates an existing connection between two controls.

对于与控件相关联的标准谓词 Part ,它们的操作应用于控件本身 (或) 的子控件。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. 这些谓词是直接显示在标头中还是出现在谓词菜单中取决于 WebPartVerbRenderMode 属性; 默认情况下,谓词出现在谓词菜单中。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. 下表列出了与各个控件关联的常见谓词 Part ,并对其操作进行了说明。The following table lists common verbs associated with the various Part controls and describes their actions.

部件控制谓词Part control verb 操作Action
最小化谓词Minimize verb 显示在区域中包含的每个服务器控件的谓词菜单中 WebPartZoneBaseAppears in the verbs menu of each server control contained in a WebPartZoneBase zone. 将控件减少到最小表示形式,隐藏其 UI 中除还原谓词以外的所有内容。Reduces the control to a minimal representation, hiding everything in its UI except the restore verb.
还原谓词Restore verb 显示在区域中包含的每个服务器控件的谓词菜单中 WebPartZoneBaseAppears 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 显示在区域中包含的每个服务器控件的谓词菜单中 WebPartZoneBaseAppears 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 WebPartZoneBase如果页面处于连接显示模式,并且控件可以形成连接,则将显示在区域中包含的控件的谓词菜单中。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 如果控件是以编程方式添加到页中的,则显示在区域中包含的控件的谓词菜单中 WebPartZoneBase ,而不是以持久性格式) (声明的。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 WebPartZoneBase如果页面旨在允许编辑控件并且页处于编辑显示模式,则将显示在区域中包含的控件的谓词菜单中。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. 选择要编辑的控件并打开编辑 UI。Selects the control for editing and opens the editing UI.
导出谓词Export verb WebPartZoneBase如果为导出启用了控件和应用程序,则在区域中包含的控件的谓词菜单中显示。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. 有关详细信息,请参见 ExportMode 属性。For details, see the ExportMode property.
帮助谓词Help verb WebPartZoneBase如果控件旨在提供帮助文件,则显示在区域中包含的控件的谓词菜单中。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.

除了随 Web 部件控件集一起提供的标准谓词,还可以创建自定义谓词。Along with the standard verbs that are provided with the Web Parts control set, you can also create custom verbs. 创建自定义谓词的常见方案是创建与控件相关联的谓词 PartA 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. 创建此类谓词的基本方法是从 WebPartVerb 类继承,以创建一个或多个自定义谓词。The basic approach for creating such verbs is to inherit from the WebPartVerb class to create one or more custom verbs. 然后创建一个从基类继承的控件 WebPart ,并将自定义 WebPartVerb 对象添加到 WebPartVerbCollection 集合中。Then create a control that inherits from the WebPart base class and add the custom WebPartVerb objects to a WebPartVerbCollection collection. 然后,可以将此集合添加到 Verbs 控件的集合,这将导致自定义谓词在运行时自动显示在控件的谓词菜单上。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. 与标准谓词一样,可以在控件上以编程方式访问自定义谓词 WebPartAs with the standard verbs, you can access the custom verbs programmatically on a WebPart control.

Web 部件应用程序可以使用不是从类继承的服务器控件 WebPart ,如自定义控件、用户控件或 ASP.NET 控件。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. 如果将这些服务器控件添加到 WebPartZoneBase 区域中,则会在运行时使用对象动态包装这些服务器控件, GenericWebPart 使其能够作为运行时 WebPart 控件运行。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. 若要向不从类继承的服务器控件添加自定义谓词 WebPart ,则服务器控件必须实现该 IWebActionable 接口并重写其 Verbs 属性。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. 例如,你可以创建一个状态,指示已选择谓词,然后在 UI 中提供相应的更改,以通知用户已选择了谓词。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.

WebPartVerb类不公开任何唯一方法; 它公开的方法都是基本方法的所有重写。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. Checked属性指示当前是否选择了谓词。The Checked property indicates whether a verb is currently selected. ClientClickHandlerServerClickHandler 属性引用类中的相应处理程序 (如果任何) 用于客户端和服务器单击事件。The ClientClickHandler and ServerClickHandler properties refer to the respective handlers within the class (if any exist) for client and server click events. Description当用户将鼠标指针放在 UI 中的谓词上时,属性包含的文本描述了工具提示中谓词的用途。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. Enabled属性指示谓词的当前状态,它确定用户是否可以单击谓词并执行其操作。The Enabled property indicates the current status of a verb, which determines whether a user can click the verb and execute its action. ID属性为 verb 对象提供唯一的 ID。The ID property provides a unique ID for the verb object. ImageUrl属性包含一个图像的 URL,该图像可用于表示 UI 中用于表示默认呈现 (通常) 按钮或超链接的谓词。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). Text属性包含在 UI 中的谓词上直接显示的标签文本。The Text property contains the label text that appears directly on the verb in the UI. 重写的 Visible 属性确定谓词当前是否显示在 UI 中。The overridden Visible property determines whether a verb is currently displayed in the UI. 谓词通常在 Web 部件应用程序中的不同时间隐藏或禁用;例如,仅当页面上存在适当的控件、设置和显示模式时,才会显示 (的专业谓词,如编辑谓词和连接谓词) ,以使这些谓词能够执行有意义的操作。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.

用于处理谓词的其他关键成员包括 WebPartZoneBase.OnCreateVerbs 方法,该方法是可重写的事件处理程序,用于谓词创建过程的自定义处理和 WebPartZoneBase.CreateVerbs 事件。Other key members for working with verbs include the WebPartZoneBase.OnCreateVerbs method, which is an event handler that can be overridden for custom handling of the verb creation process, and the WebPartZoneBase.CreateVerbs event.

构造函数

WebPartVerb(String, String)

初始化 WebPartVerb 类的新实例,并将客户端单击事件处理程序与此实例相关联。Initializes a new instance of the WebPartVerb class and associates a client-side click event handler with the instance.

WebPartVerb(String, WebPartEventHandler)

初始化 WebPartVerb 类的新实例,并将服务器端单击事件处理程序与此实例相关联。Initializes a new instance of the WebPartVerb class and associates a server-side click event handler with the instance.

WebPartVerb(String, WebPartEventHandler, String)

初始化 WebPartVerb 类的新实例,并将客户端和服务器端单击事件处理程序都与此实例相关联。Initializes a new instance of the WebPartVerb class and associates both client and server-side click event handlers with the instance.

属性

Checked

获取或设置一个值,该值指示某个与自定义谓词相关联的状态当前是否处于活动状态或被选中。Gets or sets a value indicating that some state associated with a custom verb is currently active or selected.

ClientClickHandler

获取包含客户端事件处理程序的方法名称的字符串,该处理程序在 WebPartVerb 构造函数中定义。Gets the string containing the method name of the client-side event handler defined in the WebPartVerb constructor.

Description

获取或设置谓词的简短说明。Gets or sets a short description of the verb.

Enabled

获取或设置一个值,该值指示是否启用谓词。Gets or sets a value that indicates whether a verb is enabled.

ID

获取包含谓词的唯一 ID 的字符串。Gets a string containing a unique ID for a verb.

ImageUrl

获取或设置包含一个图像的 URL 的字符串,该图像在用户界面 (UI) 中表示谓词。Gets or sets a string containing a URL to an image that represents a verb in the user interface (UI).

IsTrackingViewState

获取一个值,该值指示当前是否正在跟踪谓词的视图状态。Gets a value that indicates whether view state is currently being tracked for a verb.

ServerClickHandler

获取对处理谓词服务器端单击事件的方法的引用。Gets a reference to the method that handles server-side click events for the verb.

Text

获取或设置显示在用户界面 (UI) 中的谓词的文本标签。Gets or sets the text label for a verb that is displayed in the user interface (UI).

ViewState

获取状态信息的字典,这些信息使您可以在同一页的多个请求间保存和还原服务器控件的视图状态。Gets a dictionary of state information that allows you to save and restore the view state of a server control across multiple requests for the same page.

Visible

获取或设置一个值,该值指示谓词对用户是否可见。Gets or sets a value that indicates whether a verb is visible to users.

方法

Equals(Object)

确定指定对象是否等于当前对象。Determines whether the specified object is equal to the current object.

(继承自 Object)
GetHashCode()

作为默认哈希函数。Serves as the default hash function.

(继承自 Object)
GetType()

获取当前实例的 TypeGets the Type of the current instance.

(继承自 Object)
LoadViewState(Object)

从用 SaveViewState() 方法保存的上一个页面请求还原视图状态信息。Restores view-state information from a previous page request that was saved by the SaveViewState() method.

MemberwiseClone()

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(继承自 Object)
SaveViewState()

保存自页上次回发给服务器之后所发生的 WebPartVerb 对象的视图状态更改。Saves a WebPartVerb object's view-state changes that occurred since the page was last posted back to the server.

ToString()

返回表示当前对象的字符串。Returns a string that represents the current object.

(继承自 Object)
TrackViewState()

跟踪谓词的视图状态更改,以便更改可以存储在谓词的 StateBag 对象中。Tracks view-state changes to a verb so the changes can be stored in the verb's StateBag object.

显式接口实现

IStateManager.IsTrackingViewState

通过调用 IsTrackingViewState 类的自身的 WebPartVerb 属性,可以实现 IsTrackingViewState 属性。Implements the IsTrackingViewState property by calling the WebPartVerb class's own IsTrackingViewState property.

IStateManager.LoadViewState(Object)

通过调用 LoadViewState(Object) 类自身的 IStateManager 方法,可以实现 WebPartVerb 接口的 LoadViewState(Object) 方法。Implements the LoadViewState(Object) method of the IStateManager interface by calling the WebPartVerb class's own LoadViewState(Object) method.

IStateManager.SaveViewState()

通过调用 SaveViewState() 类自身的 WebPartVerb 方法,可以实现 SaveViewState() 方法。Implements the SaveViewState() method by calling the WebPartVerb class's own SaveViewState() method.

IStateManager.TrackViewState()

通过调用 TrackViewState() 类自身的 WebPartVerb 方法,可以实现 TrackViewState() 方法。Implements the TrackViewState() method by calling the WebPartVerb class's own TrackViewState() method.

适用于

另请参阅