WebControl.Attributes プロパティ

定義

コントロールのプロパティに対応しない任意の属性 (表示専用) のコレクションを取得します。

public:
 property System::Web::UI::AttributeCollection ^ Attributes { System::Web::UI::AttributeCollection ^ get(); };
[System.ComponentModel.Browsable(false)]
public System.Web.UI.AttributeCollection Attributes { get; }
[<System.ComponentModel.Browsable(false)>]
member this.Attributes : System.Web.UI.AttributeCollection
Public ReadOnly Property Attributes As AttributeCollection

プロパティ値

AttributeCollection

名前と値の組み合わせの AttributeCollection

属性

次の例は、コントロールがフォーカスを Attributes 失ったときに JavaScript コマンドを実行するために a WebControl のプロパティを使用する方法を TextBox 示しています。

注意

次のコード サンプルでは、シングル ファイル コード モデルを使用します。分離コード ファイルに直接コピーした場合、正しく動作しない場合があります。 このコード サンプルは、拡張子が .aspx の空のテキスト ファイルにコピーする必要があります。 Web Forms コード モデルの詳細については、「ページ コード モデルの ASP.NET Web Forms」を参照してください。

重要

この例には、ユーザー入力を受け付けるテキスト ボックスがあります。これにより、セキュリティが脆弱になる可能性があります。 既定では、ASP.NET Web ページによって、ユーザー入力にスクリプトまたは HTML 要素が含まれていないかどうかが検証されます。 詳細については、「スクリプトによる攻略の概要」を参照してください。


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

 <!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>
    <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 tap out of this text box" 
     runat="server"/>  
 
 </form>
 </body>
 </html>

<%@ Page Language="VB" AutoEventWireup="True" %>

 <!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>
    <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 tap out of this text box" 
     runat="server"/>  
 
 </form>
 </body>
 </html>

注釈

コレクション Attributes には、Web サーバー コントロールの開始タグで宣言されているすべての属性のコレクションが含まれています。 これにより、Web サーバー コントロールに関連付けられている属性をプログラムで制御できます。 コレクションに属性を追加するか、コレクションから属性を削除できます。

注意

このプロパティは、ブラウザーの設定に関係なく、コントロールの開始タグ内のコレクション内のすべての属性でレンダリングされます。 すべてのブラウザーで、レンダリングされるすべての属性がサポートされているわけではありません。 サポートされていない属性は、通常、ブラウザーによって無視されます。

注意

コレクションを使用してAttributesインスタンスにクライアント側スクリプトをWebControl追加することはできません。 クライアント側スクリプトを追加するには、コントロールの ClientScript プロパティを Page 使用します。

適用対象

こちらもご覧ください