Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

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.5.1, 4.5, 4

Windows Phone 8.1, Windows Phone 8, Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

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

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.