次の方法で共有


AttributeCollection.Item プロパティ

サーバー コントロールに指定されている属性値を取得または設定します。

名前空間: System.Web.UI
アセンブリ: System.Web (system.web.dll 内)

構文

'宣言
Public Default Property Item ( _
    key As String _
) As String
'使用
Dim instance As AttributeCollection
Dim key As String
Dim value As String

value = instance(key)

instance(key) = value
public string this [
    string key
] { get; set; }
public:
property String^ default [String^] {
    String^ get (String^ key);
    void set (String^ key, String^ value);
}
/** @property */
public String get_Item (String key)

/** @property */
public void set_Item (String key, String value)
適用できません。

パラメータ

  • key
    コレクション内の属性の位置。

プロパティ値

属性値。

解説

このプロパティを使用して、ASP.NET サーバー コントロールに属性を追加したり、このコントロールから属性を取得できます。

トピック 場所
方法 : Web フォーム ページのコントロールの HTML 属性を読み取る Visual Studio ASP .NET での Web アプリケーションの作成
方法 : Web フォーム ページのコントロールの HTML 属性を読み取る Visual Studio ASP .NET での Web アプリケーションの作成
方法 : Web フォーム ページのコントロールの HTML 属性を読み取る ASP .NET Web アプリケーションの作成

使用例

ダイナミック HTML onblur 属性を設定し、TextBox Web サーバー コントロールがフォーカスを失ったときに ECMAScript (JavaScript) コマンドを実行する例を次に示します。

<!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>
   
<!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>
   

プラットフォーム

Windows 98,Windows Server 2000 SP4,Windows CE,Windows Millennium Edition,Windows Mobile for Pocket PC,Windows Mobile for Smartphone,Windows Server 2003,Windows XP Media Center Edition,Windows XP Professional x64 Edition,Windows XP SP2,Windows XP Starter Edition

Microsoft .NET Framework 3.0 は Windows Vista,Microsoft Windows XP SP2,および Windows Server 2003 SP1 でサポートされています。

バージョン情報

.NET Framework

サポート対象 : 3.0,2.0,1.1,1.0

参照

関連項目

AttributeCollection クラス
AttributeCollection メンバ
System.Web.UI 名前空間
Attributes
Attributes