Export (0) Print
Expand All

AttributeCollection.Add Method

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

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

public void Add (
	string key,
	string value
public void Add (
	String key, 
	String value
public function Add (
	key : String, 
	value : String
Not applicable.



The attribute name.


The attribute value.

The following example demonstrates how to use the Add method to add an attribute to an ASP.NET server control's AttributeCollection programmatically.

<%@ Page Language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">
    protected void SubmitBtn_Click(object sender, EventArgs e)
        firstselect.Attributes.Add("Multiple", "True");

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>AttributeCollection Example</title>

    <form id="form1" runat="server">
    Make a selection:
    <select id="firstselect" 

    <input type="submit" 
           value="modify attribute" 

Windows 98, Windows Server 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0

Community Additions

© 2014 Microsoft