WebControl.Attributes プロパティ
アセンブリ: System.Web (system.web.dll 内)

Public ReadOnly Property Attributes As AttributeCollection
public AttributeCollection Attributes { get; }
名前と値の組み合わせの AttributeCollection。

Attributes コレクションには、Web サーバー コントロールの開始タグで宣言されたすべての属性のコレクションが格納されます。これによって、Web サーバー コントロールに関連付けられた属性をプログラムで制御できます。コレクションに属性を追加したり、コレクションから属性を削除したりできます。
![]() |
---|
このプロパティは、ブラウザの設定に関係なく、コントロールの開始タグで宣言されたコレクション内のすべての属性を使用して表示されます。表示されるすべての属性をサポートしないブラウザもあります。サポートされない属性は、通常、ブラウザで無視されます。 |

WebControl の Attributes プロパティを使用して、TextBox コントロールがフォーカスを失ったときに、JavaScript コマンドを実行する方法の例を次に示します。
![]() |
---|
次のコード サンプルはシングルファイル コード モデルを使用しており、分離コード ファイルに直接コピーされた場合は正常に動作しない可能性があります。このコード サンプルは、拡張子が .aspx の空のテキスト ファイルにコピーする必要があります。Web フォームのコード モデルの詳細については、「ASP.NET Web ページのコード モデル」を参照してください。 |
<%@ Page Language="VB" AutoEventWireup="True" %> <html> <head> <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 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="C#" AutoEventWireup="True" %> <html> <head> <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 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="JScript" AutoEventWireup="True" %> <html> <head> <script language="JSCRIPT" runat="server"> function Page_Load(sender : Object, e : EventArgs){ TextBox1.Attributes("onblur") = "javascript:alert('Focus lost from text box!!');" } </script> </head> <body> <h3>Attributes Property of a Web Control</h3> <form runat="server"> <asp:TextBox id="TextBox1" columns=54 Text="Click here and then tab out of this text box" runat="server"/> </form> </body> </html>
<html> <head> <script language="C#" runat="server"> </script> </head> <body> <h3><font face="Verdana">Attributes Property of a Web Control</font></h3> <form runat="server"> <asp:TextBox id="TextBox1" columns=54 Text="Click here and then tap out of this text box" runat="server"/> </form> </body> </html>

Windows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


Weblioに収録されているすべての辞書からWebControl.Attributes プロパティを検索する場合は、下記のリンクをクリックしてください。

- WebControl.Attributes プロパティのページへのリンク