This documentation is archived and is not being maintained.

AttributeCollection.Item Property

Gets or sets a specified attribute value for a server control.

[C#] In C#, this property is the indexer for the AttributeCollection class.

[Visual Basic]
Public Default Property Item( _
   ByVal key As String _
) As String
[C#]
public string this[
 string key
] {get; set;}
[C++]
public: __property String* get_Item(
 String* key
);
public: __property void set_Item(
 String* key,
   String*
);
[JScript]
returnValue = AttributeCollectionObject.Item(key);
AttributeCollectionObject.Item(key) = returnValue;
-or-
returnValue = AttributeCollectionObject(key);
AttributeCollectionObject(key) = returnValue;

[JScript] In JScript, you can use the default indexed properties defined by a type, but you cannot explicitly define your own. However, specifying the expando attribute on a class automatically provides a default indexed property whose type is Object and whose index type is String.

Arguments [JScript]

key
The location of the attribute within the collection.

Parameters [Visual Basic, C#, C++]

key
The location of the attribute within the collection.

Property Value

The attribute value.

Remarks

You can add an attribute to or retrieve one from an ASP.NET server control using this property.

Example

[Visual Basic, C#] The following example demonstrates setting a dynamic HTML onblur attribute to run a Javascript command when a TextBox Web server control loses focus.

[Visual Basic] 
<html>
<head>
   <script language="VB" runat="server">

       Sub Page_Load(sender As Object, e As EventArgs)
          TextBox1.Attributes("onblur")="javascript:alert('Hello! Focus lost from text box!!');"   
       End Sub
   </script>

</head>
<body>
   <h3>Attributes Property of a Web Control</h3>
<form runat="server">

   <asp:TextBox id="TextBox1" columns=54 
    Text="Click here and then tab out of this text box" 
    runat="server"/>  

</form>
</body>
</html>
   

[C#] 
<html>
<head>
   <script language="C#" runat="server">

       void Page_Load(Object sender, EventArgs e) {
          TextBox1.Attributes["onblur"]="javascript:alert('Hello! Focus lost from text box!!');";    
       }
   </script>

</head>
<body>
   <h3>Attributes Property of a Web Control</h3>
<form runat="server">

   <asp:TextBox id="TextBox1" columns=54 
    Text="Click here and then tab out of this text box" 
    runat="server"/>  

</form>
</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

AttributeCollection Class | AttributeCollection Members | System.Web.UI Namespace | HtmlControl.Attributes | WebControl.Attributes

Show: