WebControl.IsEnabled 属性


获取一个值,该值指示是否启用控件。Gets a value indicating whether the control is enabled.

protected public:
 property bool IsEnabled { bool get(); };
protected internal bool IsEnabled { get; }
member this.IsEnabled : bool
Protected Friend ReadOnly Property IsEnabled As Boolean


如果启用 WebControl 对象,则为 true;否则为 falsetrue if the WebControl object is enabled; otherwise, false.


这是一个只读属性。This is a read-only property. 如果要禁用控件,请将其Enabled属性设置为。 falseIf you want to disable a control, you set its Enabled property to false.

如果控件不包含在另一个控件中,则该IsEnabled属性的值始终与Enabled属性的值相同。If a control is not contained by another control, the value of the IsEnabled property is always the same as the value of the Enabled property.

如果IsEnabled控件是另一个控件的子控件并且Enabled满足以下所有条件,则该属性的值与属性不同:The IsEnabled property has a value that is different from the Enabled property if a control is a child of another control and if all the following circumstances are true:

  • 父控件的Enabled属性值IsEnabled或属性值为falseThe value of the Enabled property or the IsEnabled property of the parent control is false.

  • 子控件的true Enabled属性设置为。The Enabled property of the child control is set to true.

在这种情况下,子控件继承父控件的禁用状态。In this situation, the child control inherits the disabled state of the parent control. IsEnabled控件的属性将返回false以指示控件已禁用,即使子控件未通过将其Enabled属性设置为false而显式禁用。The IsEnabled property of the child control returns false to indicate that the control is disabled even though the child control was not explicitly disabled by setting its Enabled property to false. 父控件本身可能会将其Enabled属性设置为true ,但可能会从其父控件继承禁用状态,依此类推。The parent control itself might have its Enabled property set to true but might inherit the disabled state from its parent, and so on.

当 ASP.NET 呈现服务器控件的 HTML 元素时,它通过设置disabled元素的特性或其 CSS class特性来将元素标记为禁用。When ASP.NET renders HTML elements for a server control, it marks the elements as disabled by setting their disabled attribute or their CSS class attribute. 有关详细信息,请参阅 SupportsDisabledAttributeControlRenderingCompatibilityVersionFor more information, see SupportsDisabledAttribute and ControlRenderingCompatibilityVersion.