JavaScript Editor jscript editor     Web designer 

Main Page

This example reads the attributes rendered for a TextBox Web server control and an HtmlInputButton control. The code reads the Keys collection of the AttributeCollection object of each individual control. For each key item, the code extracts the corresponding value by getting the value of the corresponding Item element.


Visual BasicВ CopyCode imageCopy Code
Response.Write(Button1.Attributes.Item("Style") & "<BR>")
Dim key As String
For Each key In Button1.Attributes.Keys
    Response.Write(key & "=" & Button1.Attributes.Item(key) & "<BR>")
For Each key In Submit1.Attributes.Keys
    Response.Write(key & "=" & Submit1.Attributes.Item(key) & "<BR>")
C#В CopyCode imageCopy Code
Response.Write(Button1.Attributes[("Style")] + "<BR>");

//String key;

foreach ( String key in Button1.Attributes.Keys)
    Response.Write(key + "=" + Button1.Attributes[key] + "<BR>");
foreach ( String key in Submit1.Attributes.Keys)
    Response.Write(key + "=" + Submit1.Attributes[key] + "<BR>");

Compiling the Code

This example requires:

  • An ASP.NET Web page.

  • A Button Web control named Button1.

  • An HtmlInputButton control whose ID attribute is set to Submit1.

Robust Programming

If you specify an invalid attribute name for the Item element, the return value is an empty string.

Web server controls return only the attributes that do not have corresponding strongly typed properties.

See Also

JavaScript Editor jscript editor     Web designer