WebPartZoneBase.CloseVerb 属性

定义

获取对 WebPartVerb 对象的引用,该对象使最终用户能够关闭区域中的 WebPart 控件。Gets a reference to a WebPartVerb object that enables end users to close the WebPart controls in a zone.

public:
 virtual property System::Web::UI::WebControls::WebParts::WebPartVerb ^ CloseVerb { System::Web::UI::WebControls::WebParts::WebPartVerb ^ get(); };
[System.Web.UI.PersistenceMode(System.Web.UI.PersistenceMode.InnerProperty)]
public virtual System.Web.UI.WebControls.WebParts.WebPartVerb CloseVerb { get; }
member this.CloseVerb : System.Web.UI.WebControls.WebParts.WebPartVerb
Public Overridable ReadOnly Property CloseVerb As WebPartVerb

属性值

使最终用户能够关闭 WebPartVerb 控件的 WebPartA WebPartVerb that enables end users to close WebPart controls.

属性

示例

下面的代码示例演示如何使用 WebPartZone 控件上的 CloseVerb 属性。The following code example demonstrates the use of the CloseVerb property on a WebPartZone control. 要使代码示例正常运行,您需要 HelpVerb 属性的 "示例" 部分中的所有代码。For the code example to work, you need all the code from the Example section of the HelpVerb property.

下面的代码示例部分来自分部类,并包含用于切换是否启用或禁用帮助谓词的代码。The following part of the code example is from the partial class, and contains the code that toggles whether the help verb is enabled or disabled.

protected void CheckBoxList1_SelectedItemIndexChanged(Object sender, EventArgs e)
{
  foreach (ListItem item in CheckBoxList1.Items)
  {
    WebPartVerb theVerb;
    switch (item.Value)
    {
      case "close":
        theVerb = WebPartZone1.CloseVerb;
        break;
      case "export":
        theVerb = WebPartZone1.ExportVerb;
        break;
      case "delete":
        theVerb = WebPartZone1.DeleteVerb;
        break;
      case "minimize":
        theVerb = WebPartZone1.MinimizeVerb;
        break;
      case "restore":
        theVerb = WebPartZone1.RestoreVerb;
        break;
      default:
        theVerb = null;
        break;
    }

    if (item.Selected)
      theVerb.Enabled = true;
    else
      theVerb.Enabled = false;
  }
}
Protected Sub CheckBoxList1_SelectedItemIndexChanged(ByVal sender As [Object], ByVal e As EventArgs)
  Dim item As ListItem
  For Each item In CheckBoxList1.Items
    Dim theVerb As WebPartVerb
    Select Case item.Value
      Case "close"
        theVerb = WebPartZone1.CloseVerb
      Case "export"
        theVerb = WebPartZone1.ExportVerb
      Case "delete"
        theVerb = WebPartZone1.DeleteVerb
      Case "minimize"
        theVerb = WebPartZone1.MinimizeVerb
      Case "restore"
        theVerb = WebPartZone1.RestoreVerb
      Case Else
        theVerb = Nothing
    End Select

    If item.Selected Then
      theVerb.Enabled = True
    Else
      theVerb.Enabled = False
    End If
  Next item

End Sub

此代码示例的另一部分是承载自定义控件并包含 UI 的网页。The other part of the code example is the Web page that hosts the custom control and contains the UI. 请注意,区域中的声明性 <CloseVerb> 元素设置表示 WebPart 控件的谓词菜单中的 "关闭" 谓词的特定文本。Notice that the declarative <CloseVerb> element in the zone sets the specific text that represents the close verb in the verbs menu for the WebPart control.

<asp:WebPartZone ID="WebPartZone1" Runat="server">
  <CloseVerb Text="Close WebPart" />
  <HelpVerb Text="View Help" />
  <ExportVerb Text="Export WebPart Definition" />
  <DeleteVerb Text ="Delete WebPart" />
  <MinimizeVerb Description="Minimize the control" />
  <RestoreVerb Description="Restore the control" />
  <ZoneTemplate>
  </ZoneTemplate>  
</asp:WebPartZone>
<asp:WebPartZone ID="WebPartZone1" Runat="server">
  <CloseVerb Text="Close WebPart" />
  <HelpVerb Text="View Help" />
  <ExportVerb Text="Export WebPart Definition" />
  <DeleteVerb Text ="Delete WebPart" />
  <MinimizeVerb Description="Minimize the control" />
  <RestoreVerb Description="Restore the control" />
  <ZoneTemplate>
  </ZoneTemplate>  
</asp:WebPartZone>

另请注意,由于代码示例中使用的基础自定义 WebPart 控件(名为 TextDisplayWebPart)将 AllowClose 属性设置为其构造函数中的 false,因此目录中的 <aspSample:TextDisplayPart> 元素必须将 AllowClose 属性设置为 true,以便可以在下面的代码示例中关闭控件。Notice also that, because the underlying custom WebPart control--named TextDisplayWebPart-- used in the code example sets the AllowClose property to false in its constructor, the <aspSample:TextDisplayPart> element in the catalog must set the AllowClose property to true, so that the control can be closed in the following code example.

<asp:CatalogZone ID="CatalogZone1" Runat="server">
  <ZoneTemplate>
    <asp:DeclarativeCatalogPart ID="DeclarativeCatalogPart1" 
      Runat="server">
      <WebPartsTemplate>
        <aspSample:TextDisplayWebPart 
          runat="server"   
          id="textwebpart" 
          title = "Text Content WebPart" 
          width="350px" 
          AllowClose="true"
          ExportMode="All"
          HelpMode="Modal"
          HelpUrl="TextWebPartHelp.htm" />            
      </WebPartsTemplate>
    </asp:DeclarativeCatalogPart> 
    <asp:PageCatalogPart ID="PageCatalogPart1" Runat="server" />
  </ZoneTemplate>
</asp:CatalogZone>
<asp:CatalogZone ID="CatalogZone1" Runat="server">
  <ZoneTemplate>
    <asp:DeclarativeCatalogPart ID="DeclarativeCatalogPart1" 
      Runat="server">
      <WebPartsTemplate>
        <aspSample:TextDisplayWebPart 
          runat="server"   
          id="textwebpart" 
          title = "Text Content WebPart" 
          width="350px" 
          AllowClose="true"
          ExportMode="All"
          HelpMode="Modal"
          HelpUrl="TextWebPartHelp.htm" />            
      </WebPartsTemplate>
    </asp:DeclarativeCatalogPart> 
    <asp:PageCatalogPart ID="PageCatalogPart1" Runat="server" />
  </ZoneTemplate>
</asp:CatalogZone>

在浏览器中加载页面后,将页面切换到目录显示模式,然后将 TextDisplayWebPart 控件添加到页面。After you load the page in a browser, switch the page into catalog display mode, and add the TextDisplayWebPart control to the page. 您可以使用此复选框来启用和禁用关闭谓词,还可以单击谓词菜单中的 "关闭 WebPart谓词" 关闭控件。You can use the check boxes to enable and disable the close verb, and you can click the Close WebPart verb in the verbs menu to close the control. 关闭控件后,如果将页返回到目录显示模式,则可以单击 "目录",选择您关闭的 TextDisplayWebPart 控件的原始实例,然后在页面上重新打开它。After you close the control, if you return the page to catalog display mode, you can click the Page Catalog, select the original instance of the TextDisplayWebPart control that you closed, and reopen it on the page.

注解

CloseVerb 属性引用的关闭谓词显示在区域中每个 WebPart 控件的谓词菜单中。The close verb referenced by the CloseVerb property appears in the verbs menu of each WebPart control in a zone.

关闭控件会将其从页上的交互中移除,不过,如果开发人员提供了相应的用户界面(UI)(例如包含 PageCatalogPart 控件的 CatalogZone 区域),则用户可以将页面切换到 CatalogDisplayMode,并将以前关闭的控件实例添加回页面。Closing a control removes it from interaction on a page, although if developers provide the appropriate user interface (UI), such as a CatalogZone zone that contains a PageCatalogPart control, a user can switch the page into CatalogDisplayMode and add a previously closed instance of a control back to the page.

适用于

另请参阅