WebPartZoneBase.CloseVerb 属性

定义

获取对 WebPartVerb 对象的引用,该对象使最终用户能够关闭区域中的 WebPart 控件。

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; }
[<System.Web.UI.PersistenceMode(System.Web.UI.PersistenceMode.InnerProperty)>]
member this.CloseVerb : System.Web.UI.WebControls.WebParts.WebPartVerb
Public Overridable ReadOnly Property CloseVerb As WebPartVerb

属性值

使最终用户能够关闭 WebPartVerb 控件的 WebPart

属性

示例

下面的代码示例演示如何在 CloseVerb 控件上使用 WebPartZone 属性。 要使代码示例正常工作,需要属性的 Example 节 HelpVerb 中的所有代码。

代码示例的以下部分来自分部类,包含切换帮助谓词是启用或禁用的代码。

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 的网页。 请注意,区域中的声明性 <CloseVerb> 元素设置特定文本,该文本表示控件的谓词菜单中的 WebPart 结束谓词。

<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>

另请注意,由于代码示例中使用的名为 TextDisplayWebPart-- 的基础自定义WebPart控件在其构造函数中将 属性false设置为 AllowClose ,因此目录中的 <aspSample:TextDisplayPart> 元素必须将 属性设置为 AllowClosetrue,以便可以在以下代码示例中关闭控件。

<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 添加到页面。 可以使用复选框来启用和禁用 close 谓词,并且可以单击谓词菜单中的 “关闭 WebPart” 谓词以关闭控件。 关闭控件后,如果将页面返回到目录显示模式,则可以单击 “页面目录”,选择关闭的 TextDisplayWebPart 控件的原始实例,然后在页面上重新打开它。

注解

属性引用的 CloseVerb 关闭谓词显示在区域中每个 WebPart 控件的谓词菜单中。

关闭控件会将其从页面上的交互中删除,但如果开发人员 (UI) (例如 CatalogZone 包含 PageCatalogPart 控件的区域)提供相应的用户界面,则用户可以将页面 CatalogDisplayMode 切换到 ,并将以前关闭的控件实例添加回页面。

适用于

另请参阅