This documentation is archived and is not being maintained.

HtmlControl.Style Property

Gets a collection of all cascading style sheet (CSS) properties applied to a specified HTML server control in the .aspx file.

[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 object that contains the style properties for the HTML server control.

Remarks

Use this property to programmatically access the style properties of the HTML server control.

For additional information on the CSS style collection, see the System.Web.UI.CssStyleCollection class.

Example

[Visual Basic, C#, JScript] The following example demonstrates how to use the Style property to determine the style properties of an HtmlSelect control.

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

<html>

<script language="VB" runat="server">
Sub Page_Load(sender As Object, e As EventArgs)
    Message.InnerHtml = "<h4>" & "The select box's style collection contains:" & "</h4>"
    
    Dim keys As IEnumerator = Select1.Style.Keys.GetEnumerator()
    
    While keys.MoveNext()
        Dim key As String = CType(keys.Current, String)
        Message.InnerHtml &= key & "=" & Select1.Style(key) & "<br>"
    End While 
End Sub 'Page_Load 

</script>

<body>

   <h3>HtmlControl Style Collection Example</h3>

   Make a selection:

   <select id="Select1" 
           style="font: 12pt verdana;
                 background-color:yellow;
                 color:red;" 
           runat="server">

      <option>Item 1</option>
      <option>Item 2</option>
      <option>Item 3</option>

   </select>

   <p>

   <span id="Message" MaintainState="false" runat="server" />
   

</body>
</html>
   

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

<html>

<script language="C#" runat="server">
   void Page_Load(Object sender, EventArgs e) 
   {
      Message.InnerHtml = "<h4>The select box's style collection contains:</h4>";
     
      IEnumerator keys = Select.Style.Keys.GetEnumerator();

      while (keys.MoveNext()) 
      {

         String key = (String)keys.Current;
         Message.InnerHtml += key + "=" + Select.Style[key] + "<br>";

      }
   }

</script>

<body>

   <h3>HtmlControl Style Collection Example</h3>

   Make a selection:

   <select id="Select" 
           style="font: 12pt verdana;
                 background-color:yellow;
                 color:red;" 
           runat="server">

      <option>Item 1</option>
      <option>Item 2</option>
      <option>Item 3</option>

   </select>

   <p>

   <span id="Message" MaintainState="false" runat="server" />
   

</body>
</html>
   

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

<html>

<script language="jscript" runat="server">
function Page_Load(sender: Object, e: EventArgs){
    Message.InnerHtml = "<h4>The select box's style collection contains:</h4>"
    
    var keys: IEnumerator = Select1.Style.Keys.GetEnumerator()
    
    while(keys.MoveNext()){
        var key: String = String(keys.Current)
        Message.InnerHtml += key + "=" + Select1.Style(key) + "<br>"
    }
}

</script>

<body>

   <h3>HtmlControl Style Collection Example</h3>

   Make a selection:

   <select id="Select1" 
           style="font: 12pt verdana;
                 background-color:yellow;
                 color:red;" 
           runat="server">

      <option>Item 1</option>
      <option>Item 2</option>
      <option>Item 3</option>

   </select>

   <p>

   <span id="Message" MaintainState="false" runat="server" />
   

</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 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

See Also

HtmlControl Class | HtmlControl Members | System.Web.UI.HtmlControls Namespace | System.Web.UI.CssStyleCollection | HtmlSelect

Show: