WebControl.DisabledCssClass 属性

定义

获取或设置要在控件处于禁用状态时应用于呈现的 HTML 元素的 CSS 类。Gets or sets the CSS class to apply to the rendered HTML element when the control is disabled.

public:
 static property System::String ^ DisabledCssClass { System::String ^ get(); void set(System::String ^ value); };
public static string DisabledCssClass { get; set; }
member this.DisabledCssClass : string with get, set
Public Shared Property DisabledCssClass As String

属性值

应在控件处于禁用状态时应用于呈现的 HTML 元素的 CSS 类。The CSS class that should be applied to the rendered HTML element when the control is disabled. 默认值为“aspNetDisabled”。The default value is "aspNetDisabled".

示例

下面的Label示例演示SupportsDisabledAttributefalse CssClass属性为、属性具有其默认值并且属性为空时,已禁用控件的呈现的 HTML。 DisabledCssClassThe 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>

下面的示例显示了在相同条件下呈现的 HTML, CssClass但属性的值为 "SampleStyle":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>

有关更多信息,请参见 SupportsDisabledAttribute 属性。For more information, see the SupportsDisabledAttribute property.

注解

此属性可用于更改为各个 Web 控件的DisabledCssClass属性呈现的名称。This property can be used to change the name that is rendered for the DisabledCssClass property of individual Web controls. 默认情况下,此属性将返回 "aspNetDisabled"。By default, this property returns "aspNetDisabled".

SupportsDisabledAttribute在派生类中被重写以false返回时DisabledCssClassclass属性的值将呈现为控件的 HTML 元素的特性的值。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. 在这种情况下,如果CssClass属性中存在值,则这两个 CSS 类将应用于呈现的 HTML 元素。In that case, if there is a value in the CssClass property, both CSS classes will be applied to the rendered HTML element. 属性将包含DisabledCssClass属性的值,后跟CssClass属性的值(用空格分隔)。 classThe class attribute will consist of the value of the DisabledCssClass property followed by the value of the CssClass property, separated by a space.

此属性是静态的,这意味着您只能为WebControl类设置此属性。This property is static, which means that you can set it only for the WebControl class. 设置为的任何值用于 Web 应用程序中的所有控件。Whatever value you set it to is used for all controls in a Web application. 不能为各个控件指定不同的值。You cannot specify different values for individual controls.

如果要使用不同于默认值 "aspNetDisabled" 的类名称,则通常会在 global.asax 文件的Application_Start方法中放置代码来执行此操作,如以下示例中所示: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:

Private Sub Application_Start(  
    ByVal sender As Object, ByVal e As EventArgs)  
    WebControl.DisabledCssClass = "customDisabledClassName"  
End Sub  
void Application_Start(object sender, EventArgs e)  
{  
    WebControl.DisabledCssClass = "customDisabledClassName";  
}  

适用于

另请参阅