AttributeCollection.Item[String] Właściwość
Definicja
Ważne
Niektóre informacje odnoszą się do produktu w wersji wstępnej, który może zostać znacząco zmodyfikowany przed wydaniem. Firma Microsoft nie udziela żadnych gwarancji, jawnych lub domniemanych, w odniesieniu do informacji podanych w tym miejscu.
Pobiera lub ustawia określoną wartość atrybutu dla kontrolki serwera.
public:
property System::String ^ default[System::String ^] { System::String ^ get(System::String ^ key); void set(System::String ^ key, System::String ^ value); };
public string this[string key] { get; set; }
member this.Item(string) : string with get, set
Default Public Property Item(key As String) As String
Parametry
- key
- String
Lokalizacja atrybutu w kolekcji.
Wartość właściwości
Wartość atrybutu.
Przykłady
W poniższym przykładzie pokazano, jak ustawić dynamiczny atrybut HTML onblur
, aby uruchomić polecenie ECMAScript (JavaScript), gdy TextBox kontrolka serwera sieci Web traci fokus.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Attributes Property of a Web Control</title>
<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 id="form1" runat="server">
<asp:TextBox id="TextBox1" columns="54"
Text="Click here and then tab out of this text box"
runat="server"/>
</form>
</body>
</html>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Attributes Property of a Web Control</title>
<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 id="form1" runat="server">
<asp:TextBox id="TextBox1" columns="54"
Text="Click here and then tab out of this text box"
runat="server"/>
</form>
</body>
</html>
Uwagi
Można dodać atrybut do lub pobrać go z kontrolki serwera ASP.NET, która używa tej właściwości.