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


UniqueID プロパティを使用して、HtmlForm コントロールに割り当てられた一意のプログラム ID を取得します。このプロパティは、ページ以外の INamingContainer 実装オブジェクト (カスタム サーバー コントロールなど) にコントロールが格納されている場合に、基本の実装をオーバーライドして定数値を返します。名前付けコンテナがページの場合、HtmlForm コントロールの ID プロパティの値が返されます。
UniqueID プロパティおよび Name プロパティは常に同じ値を返します。これは、HtmlForm コントロールの UniqueID プロパティと Name プロパティの値が同じである必要のある HtmlForm コントロールをブラウザで表示する場合に役立ちます。これらのプロパティを同期させておくために、Name プロパティは常に UniqueID プロパティの値を返します。
![]() |
---|
name 属性は、XHTML に準拠した属性ではないので、既定では ASP.NET で表示されません。XHTML 以外を表示するように ASP.NET を構成する方法の詳細については、「方法 : ASP.NET Web サイトで XHTML レンダリングを構成する」を参照してください。 |

UniqueID プロパティを使用して、HtmlForm コントロールの一意の ID を取得する方法を次のコード例に示します。
<%@ page language="VB" %> <script runat="server"> Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) ' Write the form's UniqueID to the specified Label control. Label1.Text = "The HtmlForm control's UniqueID is " _ & Form1.UniqueID + "." End Sub Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) ' Write the button's UniqueID to the specified Label control. Label2.Text = "This Button control's UniqueID is " _ & Button2.UniqueID & "." End Sub </script> <html> <head> <title>HtmlForm UniqueID Property Example</title> </head> <body> <form id="Form1" runat="server"> <h3>HtmlForm UniqueID Property Example</h3> <asp:button id="Button1" text="Get the form's UniqueID" onclick="Button1_Click" runat="server"> </asp:button> <asp:label id="Label1" runat=Server> </asp:label> <br /> <asp:button id="Button2" text="Get this button's UniqueID" onclick="Button2_Click" runat="server"> </asp:button>   ; <asp:label id="Label2" runat="server"> </asp:label> </form> </body> </html>
<%@ page language="C#" %> <script runat=Server> void Button1_Click(object sender, System.EventArgs e) { // Write the form's UniqueID to the specified Label control. Label1.Text = "The HtmlForm control's UniqueID is " + Form1.UniqueID + "."; } void Button2_Click(object sender, System.EventArgs e) { // Write the button's UniqueID to the specified Label control. Label2.Text = "This Button control's UniqueID is " + Button2.UniqueID + "."; } </script> <html> <head> <title>HtmlForm UniqueID Property Example</title> </head> <body> <form id="Form1" runat="server"> <h3>HtmlForm UniqueID Property Example</h3> <asp:button id="Button1" text="Get the form's UniqueID" onclick="Button1_Click" runat="server"> </asp:button> <asp:label id="Label1" runat=Server> </asp:label> <br /> <asp:button id="Button2" text="Get this button's UniqueID" onclick="Button2_Click" runat="server"> </asp:button> <asp:label id="Label2" runat="server"> </asp:label> </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に収録されているすべての辞書からHtmlForm.UniqueID プロパティを検索する場合は、下記のリンクをクリックしてください。

- HtmlForm.UniqueID プロパティのページへのリンク