.NET Framework Class Library
WebControlStyle 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)
Syntax
<[%$TOPIC/bx47a5t2_en-us_VS_110_1_0_0_0_0%](False)> _
Public ReadOnly Property Style As [%$TOPIC/bx47a5t2_en-us_VS_110_1_0_0_0_1%]
[[%$TOPIC/bx47a5t2_en-us_VS_110_1_0_1_0_0%](false)]
public [%$TOPIC/bx47a5t2_en-us_VS_110_1_0_1_0_1%] Style { get; }
[[%$TOPIC/bx47a5t2_en-us_VS_110_1_0_2_0_0%](false)]
public:
property [%$TOPIC/bx47a5t2_en-us_VS_110_1_0_2_0_1%]^ Style {
	[%$TOPIC/bx47a5t2_en-us_VS_110_1_0_2_0_2%]^ get ();
}
[<[%$TOPIC/bx47a5t2_en-us_VS_110_1_0_3_0_0%](false)>]
member Style : [%$TOPIC/bx47a5t2_en-us_VS_110_1_0_3_0_1%] with get

Property Value

Type: System.Web.UICssStyleCollection
A CssStyleCollection that contains the HTML style attributes to render on the outer tag of the Web server control.
Remarks

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.

NoteNote

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.

Examples

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

NoteNote

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 Forms Page Code Model.

<%@ Page Language="VB" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">

    Sub Button1_Click(sender As Object, e As EventArgs)
        If Label1.Style("visibility") = "hidden" Then
            Label1.Style("visibility") = "show"
        Else
            Label1.Style("visibility") = "hidden"
        End If
    End Sub

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head2" runat="server">
    <title>Style Property Example</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>

        <h3>Style Property of a Web Control</h3>

        <asp:Label id="Label1" Text="This is a label control." 
            BorderStyle="Solid" runat="server"/>

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

    </div>
    </form>
</body>
</html>
<%@ Page Language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">

    void Button1_Click(Object sender, EventArgs e)
    {
        if (Label1.Style["visibility"] == "hidden")
            Label1.Style["visibility"] = "show";
        else
            Label1.Style["visibility"] = "hidden";
    }

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head2" runat="server">
    <title>Style Property of a Web Control</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>

        <h3>Style Property of a Web Control</h3>

        <asp:Label id="Label1" Text="This is a label control." 
            BorderStyle="Solid" runat="server"/>

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

    </div>
    </form>
</body>
</html>
Version Information

.NET Framework

Supported in: 4.5.3, 4, 3.5, 3.0, 2.0, 1.1, 1.0
Platforms

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.