This documentation is archived and is not being maintained.

WebControl.Style Property

Gets a collection of text attributes that will be rendered as a style attribute on the outer tag of the Web server control.

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

public CssStyleCollection Style { get; }
/** @property */
public CssStyleCollection get_Style ()

public function get Style () : CssStyleCollection

Not applicable.

Property Value

A CssStyleCollection that contains the HTML style attributes to render on the outer tag of the Web server control.

Use the Style collection to manage the style attributes rendered in the outer tag of the Web server control. This property will render on all browsers for all controls.


Browsers that do not support style attributes will ignore the rendered HTML.

Any style values set through the strongly typed style properties (for example, BackColor="Red") will automatically override a corresponding value in this collection.

Values set in this collection are not automatically reflected by the strongly typed style properties.

The following example illustrates how to use the Style property to hide or display a Label control on a page.


The following code sample uses the single-file code model and may not work correctly if copied directly into a code-behind file. This code sample must be copied into an empty text file that has an .aspx extension. For more information on the Web Forms code model, see ASP.NET Web Page Code Model.

<%@ Page Language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 

<script runat="server">
    void Button1_Click(Object sender, EventArgs e)
        if (Label1.Style["visibility"] == "hidden")
            Label1.Style["visibility"] = "show";
            Label1.Style["visibility"] = "hidden";
<html xmlns="" >
<head id="Head2" runat="server">
    <title>Style Property of a Web Control</title>
    <form id="form1" runat="server">
        <h3>Style Property of a Web Control</h3>
        <asp:Label id="Label1" Text="This is a label control." 
            BorderStyle="Solid" runat="server"/>

            <asp:Button id="Button1" 
                Text="Click to hide or unhide the label"
                OnClick="Button1_Click" runat="server"/>


Windows 98, Windows Server 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0