AttributeCollection.Keys Property


The .NET API Reference documentation has a new home. Visit the .NET API Browser on to see the new experience.

Gets a collection of keys to all attributes in the server control's AttributeCollection object.

Namespace:   System.Web.UI
Assembly:  System.Web (in System.Web.dll)

public ICollection Keys { get; }

Property Value

Type: System.Collections.ICollection

The collection of keys.

This property contains all the keys that are in the AttributeCollection of an ASP.NET server control, whether you have added them programmatically with the Add method, or declaratively.

The following example shows how to iterate through the Keys property of the AttributeCollection object for an HtmlSelect server control.

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

<script language="C#" runat="server">

    void Page_Load(Object Src, EventArgs e)
       Message.InnerHtml += 
           "<h5>The FirstSelect select box's " + 
           "Attribute collection contains:</h5>";

       IEnumerator keys = 

       while (keys.MoveNext())
           String key = (String)keys.Current;
           Message.InnerHtml += key + "=" + 
               FirstSelect.Attributes[key] + "<br />";


<html xmlns="" >
<head runat="server">
    <title>Attribute Collection Sample</title>

        <span id="Message" enableviewstate="false" 
            runat="server" />
        Make a selection:
        <select id="FirstSelect" runat="server" 
           style="padding:1; width:40; font: 16pt verdana;
           background-color:Aqua; color:black;">


.NET Framework
Available since 1.1
Return to top