Export (0) Print
Expand All

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.

[Visual Basic]
Public ReadOnly Property Style As CssStyleCollection
[C#]
public CssStyleCollection Style {get;}
[C++]
public: __property CssStyleCollection* get_Style();
[JScript]
public function get Style() : CssStyleCollection;

Property Value

A System.Web.UI.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.

Note   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.

Example

[Visual Basic, C#, JScript] The following example illustrates how to use the Style property to hide or display a Label control on a page.

[Visual Basic] 
<%@ Page Language="VB" AutoEventWireup="True" %>

<html>
 <head>
 
   <script language="VB" 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>
 
 </head>
 <body>
 
   <h3>Style Property of a Web Control</h3>
 
 <form runat="server">
 
   <asp:Label id="Label1" Text="This is a label control." 
     BorderStyle="Solid" runat="server"/>
 
   <p>
 
   <asp:Button id="Button1" Text="Click to hide/unhide the above label"
     OnClick="Button1_Click" runat="server"/>
 
 </form>
 
 </body>
 </html>
 

[C#] 
<%@ Page Language="C#" AutoEventWireup="True" %>

<html>
 <head>
 
   <script language="C#" runat="server">
 
       void Button1_Click(Object sender, EventArgs e) {
          Label1.Style["visibility"]= ((Label1.Style["visibility"]=="hidden")?"show":"hidden");
       }
 
   </script>
 
 </head>
 <body>
 
   <h3>Style Property of a Web Control</h3>
 
 <form runat="server">
 
   <asp:Label id="Label1" Text="This is a label control." 
     BorderStyle="Solid" runat="server"/>
 
   <p>
 
   <asp:Button id="Button1" Text="Click to hide/unhide the above label"
     OnClick="Button1_Click" runat="server"/>
 
 </form>
 
 </body>
 </html>
 

[JScript] 
<%@ Page Language="JScript" AutoEventWireup="True" %>

<html>
 <head>
 
   <script language="JSCRIPT" runat="server">
 
    function Button1_Click(sender : Object, e : EventArgs){
        if(Label1.Style["visibility"] == "hidden")
            Label1.Style["visibility"] = "show"
        else
            Label1.Style["visibility"] = "hidden"
    }
 
   </script>
 
 </head>
 <body>
 
   <h3>Style Property of a Web Control</h3>
 
 <form runat="server">
 
   <asp:Label id="Label1" Text="This is a label control." 
     BorderStyle="Solid" runat="server"/>
 
   <p>
 
   <asp:Button id="Button1" Text="Click to hide/unhide the above label"
     OnClick="Button1_Click" runat="server"/>
 
 </form>
 
 </body>
 </html>
 

[C++] No example is available for C++. To view a Visual Basic, C#, or JScript example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 2000, Windows XP Professional, Windows Server 2003 family

See Also

WebControl Class | WebControl Members | System.Web.UI.WebControls Namespace | System.Web.UI.CssStyleCollection

Show:
© 2014 Microsoft