System.Web.UI Namespace
Provides object-model access to all attributes declared in the opening tag of an ASP.NET server control element. This class cannot be inherited.
Attributes' case-sensitivity depends upon whether the StateBag class from which it inherits is case-sensitive or not. They return a String object as their value. If there are no attributes in the collection, they return a null reference ( Nothing in Visual Basic ).
Attributes on an HTML server control are programmatically accessible through the HtmlControl.Attributes property, which is inherited by all HTML server controls. The .NET Framework treats HTML attributes as properties of the HTML server control to which they belong.
You can also add attributes to a Web server control through the WebControl.Attributes property, which is inherited by all Web server controls. Attributes stored in this collection for a Web server control do not correspond to the strongly typed properties found on the specified Web server control.
The below code shows how to enumerate the items of the AttributeCollection object retrieved from an HtmlControl. Note that the attributes stored in this collecion reflect only the arbitrary properties that do not correspond to the properties defined in the .NET Framework for the control.
<script language="C#" runat="server">
string atts;
void showAttributes ( object src, EventArgs e ) {
IEnumerator attribs = greeting.Attributes.Keys.GetEnumerator ( );
while ( attribs.MoveNext ( ) ) {
string key = ( string ) attribs.Current;
atts += key + " = " + greeting.Attributes [ key ] + "<br>";;
}
message.Text = atts;
}
</script>
Show me
HtmlControl.Attributes WebControl.Attributes