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

属性值

如果启用 true 对象,则为 WebControl;否则为 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.

如果控件是另一个控件的子控件并且以下所有情况都为 true,则 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:

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

  • 子控件的 Enabled 属性设置为 trueThe 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.

适用于

另请参阅