AttributeCollection.Add(String, String) Método

Definição

Adiciona um atributo a um objeto AttributeCollection de controle de servidor.

public:
 void Add(System::String ^ key, System::String ^ value);
public void Add (string key, string value);
member this.Add : string * string -> unit
Public Sub Add (key As String, value As String)

Parâmetros

key
String

O nome do atributo.

value
String

O valor do atributo.

Exemplos

O exemplo a seguir mostra como usar o Add método para adicionar programaticamente um atributo a um objeto de controle AttributeCollection de servidor ASP.NET.

<%@ 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");
    }
</script>

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

 <body>
    <form id="form1" runat="server">
    <div>
    Make a selection:
    <select id="firstselect" 
            runat="server">
       <option>This</option>
       <option>That</option>
       <option>Other</option>
    </select>
    <br/><br/>

    <input type="submit" 
           id="submitbtn"
           value="modify attribute" 
           onserverclick="SubmitBtn_Click" 
           runat="server"/>
    </div>
 </form>
 </body>
 </html>
<%@ Page Language="VB" %>

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

<script runat="server">
 
    Protected Sub SubmitBtn_Click(ByVal sender As Object, ByVal e As System.EventArgs)
        FirstSelect.Attributes.Add("Multiple", "True")
    End Sub
</script>

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

 <body>
    <form id="form1" runat="server">
    <div>
    Make a selection:
    <select id="firstselect" 
            runat="server">
       <option>This</option>
       <option>That</option>
       <option>Other</option>
    </select>
    <br/><br/>

    <input type="submit" 
           id="submitbtn"
           value="modify attribute" 
           onserverclick="submitbtn_click" 
           runat="server"/>
    </div>
 </form>
 </body>
 </html>

Comentários

Se a cadeia de caracteres no value parâmetro contiver um e comercial (&), o caractere será codificado automaticamente. A representação HTML resultante é "&".

Aplica-se a

Confira também