Editar

Partilhar via


WebControl.SupportsDisabledAttribute Property

Definition

Gets a value that indicates whether the control should set the disabled attribute of the rendered HTML element to "disabled" when the control's IsEnabled property is false.

public:
 virtual property bool SupportsDisabledAttribute { bool get(); };
[System.ComponentModel.Browsable(false)]
public virtual bool SupportsDisabledAttribute { get; }
[<System.ComponentModel.Browsable(false)>]
member this.SupportsDisabledAttribute : bool
Public Overridable ReadOnly Property SupportsDisabledAttribute As Boolean

Property Value

Always true.

Attributes

Examples

The following example shows markup for a disabled Label control:

<asp:Label id="Label1" runat="server" Text="Test" Enabled="false"/>

In ASP.NET 3.5 and earlier versions, this markup renders the following HTML:

<span id="Label1" disabled="disabled">Test</span>

In ASP.NET 4, if the value of the RenderingCompatibility property is 4.0 or greater, and if the DisabledCssClass property is set to its default value, the same markup renders the following HTML:

<span id="Label1" class="aspNetDisabled">Test</span>

Remarks

In derived classes, this property indicates how ASP.NET should render HTML for a control when the control is disabled.

Disabling ASP.NET Web Controls

When the Enabled property of an ASP.NET control is set to false (that is, when the control is disabled), the intent is that ASP.NET should render the control in the page, but display it in a disabled state (typically dimmed). If a parent control is disabled, children of that control are also displayed as disabled. In that case, the child control's IsEnabled property is set to false, even though its Enabled property might be set to true.

In ASP.NET 3.5 and earlier versions, when a control's IsEnabled property is false, ASP.NET sets the disabled attribute to "disabled" in the HTML element that it renders for the control. However, the HTML 4.01 standard allows the disabled attribute only on certain elements that are used for user input. For example, the disabled attribute is allowed for input elements, but not for span elements.

Most browsers support a default disabled appearance for display-only elements that have disabled attributes. However, in order to comply with HTML standards, by default ASP.NET 4 omits invalid attributes.

How the SupportsDisabledAttribute Property is Used

If the SupportsDisabledAttribute property is true, ASP.NET renders a disabled attribute when the control is disabled. If this property is false, ASP.NET renders a class attribute when the control is disabled.

Derived classes override this property to return false if all the following conditions are true:

  • The control renders an HTML element that does not support the disabled attribute.

  • The RenderingCompatibility property indicates an ASP.NET version number lower than 4.0.

The SupportsDisabledAttribute property does not necessarily indicate whether the HTML element that is rendered for a control supports (allows) the disabled attribute. If a control's RenderingCompatibility property indicates an ASP.NET version number lower than 4.0, the value of the control's SupportsDisabledAttribute property might return true even if the rendered HTML does not support the disabled attribute.

Backward Compatibility for Disabled Controls

When you use Visual Studio to upgrade a Web project to ASP.NET 4 from an earlier version, Visual Studio automatically sets the controlRenderingCompatibilityVersion attribute in the Web.config file (which sets the RenderingCompatibility property) to the earlier version number. Because the SupportsDisabledAttribute property always returns true when the RenderingCompatibility property is lower than 4.0, this causes Web controls to render HTML for disabled controls as they did in the earlier version. If you want an upgraded Web site to render HTML using the algorithm introduced in ASP.NET 4, you can change or remove the controlRenderingCompatibilityVersion attribute. For more information, see the RenderingCompatibility property.

Setting a Disabled Appearance By Using CSS

If the SupportsDisabledAttribute property of a control is false and the control is disabled, ASP.NET sets the class attribute of the rendered HTML element to the value of the WebControl.DisabledCssClass property. The default value of the WebControl.DisabledCssClass property is "aspNetDisabled".

To provide a disabled appearance for disabled controls, you must define a CSS rule for the class that is represented by the value of the WebControl.DisabledCssClass property.

The HTML element that is rendered for a control might have more than one value in its class attribute if there is a value in its CssClass property. For more information, see the DisabledCssClass property.

Applies to

See also