This documentation is archived and is not being maintained.

AttributeCollection.Add Method

Adds an attribute to a server contol's AttributeCollection object.

[Visual Basic]
Public Sub Add( _
   ByVal key As String, _
   ByVal value As String _
)
[C#]
public void Add(
 string key,
 string value
);
[C++]
public: void Add(
 String* key,
 String* value
);
[JScript]
public function Add(
   key : String,
 value : String
);

Parameters

key
The index assigned to the new attribute in the collection.
value
The attribute to store in the collection.

Remarks

A typical scenario for you to use this method is when users personalize pages they frequently visit.

Example

[Visual Basic, C#, JScript] The following example demonstrates how to use the Add method to add an attribute to an ASP.NET server control's AttributeCollection programmatically.

[Visual Basic] 
<html>
 <script language="VB" runat="server">
    Sub SubmitBtn_Click(Src As Object, e As EventArgs)
        FirstSelect.Attributes.Add("Multiple", "True")
    End Sub
 </script>
 <body>
    <form runat="server">
    <span id="Message" MaintainState="false" runat="server" />
    <p>
    Make a selection:
    <select id="FirstSelect" padding="1" width="40" style="font: 16pt verdana;background-color:lightblue;color:black;" runat="server">
       <option>This</option>
       <option>That</option>
       <option>Other</option>
    </select><br><br>

  <input type="submit" id="SubmitBtn" OnServerClick="SubmitBtn_Click" runat="server"/>

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

[C#] 
<html>
 <script language="C#" runat="server">
    void SubmitBtn_Click(Object Src, EventArgs e){
        FirstSelect.Attributes.Add("Multiple", 
                "True");
    }
 </script>
 <body>
    <form runat="server">
    <span id="Message" MaintainState="false" runat="server" />
    <p>
    Make a selection:
    <select id="FirstSelect" padding="1" width="40" style="font: 16pt verdana;background-color:lightblue;color:black;" runat="server">
       <option>This</option>
       <option>That</option>
       <option>Other</option>
    </select><br><br>

  <input type="submit" id="SubmitBtn" OnServerClick="SubmitBtn_Click" runat="server"/>

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

[JScript] 
<html>
 <script language="JScript" runat="server">
    function SubmitBtn_Click(Src, e : EventArgs){
        FirstSelect.Attributes.Add("Multiple", 
                "True");
    }
 </script>
 <body>
    <form runat="server">
    <span id="Message" MaintainState="false" runat="server" />
    <p>
    Make a selection:
    <select id="FirstSelect" padding="1" width="40" style="font: 16pt verdana;background-color:lightblue;color:black;" runat="server">
       <option>This</option>
       <option>That</option>
       <option>Other</option>
    </select><br><br>

  <input type="submit" id="SubmitBtn" OnServerClick="SubmitBtn_Click" runat="server"/>

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

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