WebPartVerb.Enabled 属性
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
获取或设置一个值,该值指示是否启用谓词。
public:
virtual property bool Enabled { bool get(); void set(bool value); };
[System.Web.UI.Themeable(false)]
public virtual bool Enabled { get; set; }
[<System.Web.UI.Themeable(false)>]
member this.Enabled : bool with get, set
Public Overridable Property Enabled As Boolean
属性值
如果启用谓词,则为 true
;否则为 false
。 默认值为 true
。
- 属性
示例
下面的代码示例演示如何重写 Enabled 继承自 WebPartVerb的派生类中的 属性。 此源代码仅显示自定义区域的代码部分以及 WebPartVerb 替代 属性的 类。 运行示例所需的其余代码可在类概述的 WebPartVerb “示例”部分中找到。
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
注解
使用此属性可获取或设置一个值,该值指示是否启用谓词。 能够在页面和控件生命周期中的给定点启用或禁用谓词非常有用。 例如,如果开发人员希望出于任何原因阻止用户关闭区域中的WebPart控件,开发人员可以将谓词的 CloseVerb 属性值设置为 Enabledfalse
,然后将阻止用户关闭该区域中的任何控件。 默认情况下,禁用的谓词在带有视觉提示的谓词菜单中呈现,例如较浅的文本颜色。
无法通过主题或样式表主题设置此属性。 有关详细信息,请参阅 ThemeableAttribute 和 ASP.NET 主题和皮肤。