WebControl.Attributes プロパティ
定義
重要
一部の情報は、リリース前に大きく変更される可能性があるプレリリースされた製品に関するものです。 Microsoft は、ここに記載されている情報について、明示または黙示を問わず、一切保証しません。
コントロールのプロパティに対応しない任意の属性のコレクションを取得します (レンダリングのみ)。
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 。
- 属性
例
次の例は、Attributes コントロールがフォーカスを失ったときに、WebControlの TextBox プロパティを使用して JavaScript コマンドを実行する方法を示しています。
Note
次のコード サンプルでは、単一ファイルコード モデルを使用します。分離コード ファイルに直接コピーした場合、正しく動作しない可能性があります。 このコード サンプルは、.aspx拡張子が付いている空のテキスト ファイルにコピーする必要があります。 Web フォーム コード モデルの詳細については、「Web フォーム ページ コード モデル ASP.NET」を参照してください。
Important
この例には、潜在的なセキュリティ上の脅威であるユーザー入力を受け入れるテキスト ボックスがあります。 既定では、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 サーバー コントロールに関連付けられている属性をプログラムで制御できます。 コレクションに属性を追加することも、コレクションから属性を削除することもできます。
Note
このプロパティは、ブラウザーの設定に関係なく、コントロールの開始タグ内のコレクション内のすべての属性と共にレンダリングされます。 すべてのブラウザーで、レンダリングされるすべての属性がサポートされているわけではありません。 サポートされていない属性は、通常、ブラウザーによって無視されます。
Note
WebControl コレクションを使用して、Attributes インスタンスにクライアント側スクリプトを追加することはできません。 クライアント側スクリプトを追加するには、ClientScript コントロールの Page プロパティを使用します。