Export (0) Print
Expand All

CssStyleCollection.Keys Property

Gets a collection of keys to all the styles in the CssStyleCollection object for a specific HTML server control.

[Visual Basic]
Public ReadOnly Property Keys As ICollection
[C#]
public ICollection Keys {get;}
[C++]
public: __property ICollection* get_Keys();
[JScript]
public function get Keys() : ICollection;

Property Value

A collection of keys contained in the CssStyleCollection object for the specified HTML server control.

Example

[Visual Basic, C#] The following example uses the Keys property to iterate through and display all the styles contained in an HtmlInputText server control.

[Visual Basic] 
<html>
 <script language="vb" runat="server">
   Sub Page_Load(Src As Object, e As EventArgs)
      Message.InnerHtml += "<h5>The Text Box's CssStyleCollection contains:</h5>"
   
      Dim keys As IEnumerator = MyText.Style.Keys.GetEnumerator()
   
      While keys.MoveNext()
      
         Dim key As [String] = CType(keys.Current, [String])
         Message.InnerHtml += key + "=" + MyText.Style(key) + "<br>"
      End While
   End Sub 'Page_Load
 </script>

 <body>
    <span id="Message" MaintainState="false" runat="server" />
    <p>
    <b>Enter some text:</b> <br>
    <input id="MyText" type="text" value="Type a value here." 
        style="font: 14pt verdana;width:300;" runat="server"/>
 
  </body>
</html>

[C#] 
<html>
 <script language="C#" runat="server">
    void Page_Load(Object Src, EventArgs e) {
       Message.InnerHtml += "<h5>The Text Box's CssStyleCollection contains:</h5>";
       
       IEnumerator keys = MyText.Style.Keys.GetEnumerator();
 
       while (keys.MoveNext()) {
 
           String key = (String)keys.Current;
           Message.InnerHtml += key + "=" + MyText.Style[key] + "<br>";
       }
    }
 </script>
 <body>
    <span id="Message" MaintainState="false" runat="server" />
    <p>
    <b>Enter some text:</b> <br>
    <input id="MyText" type="text" value="Type a value here." 
        style="font: 14pt verdana;width:300;" runat="server"/>
 
  </body>
</html>

[C++, JScript] No example is available for C++ or JScript. To view a Visual Basic or C# 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

CssStyleCollection Class | CssStyleCollection Members | System.Web.UI Namespace | Style

Show:
© 2015 Microsoft