This documentation is archived and is not being maintained.

WebControl.DisabledCssClass Property

Gets or sets the CSS class to apply to the rendered HTML element when the control is disabled.

Namespace:  System.Web.UI.WebControls
Assembly:  System.Web (in System.Web.dll)

public static string DisabledCssClass { get; set; }
<asp:WebControl DisabledCssClass="String" />

Property Value

Type: System.String
The CSS class that should be applied to the rendered HTML element when the control is disabled. The default value is "aspNetDisabled".

This property can be used to change the name that is rendered for the DisabledCssClass property of individual Web controls. By default, this property returns "aspNetDisabled".

When SupportsDisabledAttribute is overridden in a derived class to return false, the value of the DisabledCssClass property is rendered as the value of the class attribute of the HTML element for the control. In that case, if there is a value in the CssClass property, both CSS classes will be applied to the rendered HTML element. The class attribute will consist of the value of the DisabledCssClass property followed by the value of the CssClass property, separated by a space.

This property is static, which means that you can set it only for the WebControl class. Whatever value you set it to is used for all controls in a Web application. You cannot specify different values for individual controls.

If you want to use a class name different from the default value of "aspNetDisabled", you typically put the code to do that in the Application_Start method of the Global.asax file, as shown in the following example:

void Application_Start(object sender, EventArgs e)
    WebControl.DisabledCssClass = "customDisabledClassName";

The following example shows rendered HTML for a disabled Label control when the SupportsDisabledAttribute property is false, when the DisabledCssClass property has its default value, and when the CssClass property is empty.

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

The following example shows rendered HTML under the same conditions except that the CssClass property has the value "SampleStyle":

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

For more information, see the SupportsDisabledAttribute property.

.NET Framework

Supported in: 4

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.