HtmlForm.UniqueID Property

 
System_CAPS_noteNote

The .NET API Reference documentation has a new home. Visit the .NET API Browser on docs.microsoft.com to see the new experience.

Gets the unique programmatic identifier assigned to the HtmlForm control.

Namespace:   System.Web.UI.HtmlControls
Assembly:  System.Web (in System.Web.dll)

Public Overrides ReadOnly Property UniqueID As String

Property Value

Type: System.String

The unique programmatic identifier assigned to the HtmlForm control.

Use the UniqueID property to get the unique programmatic identifier assigned to the HtmlForm control. This property overrides the base implementation to return a constant value when the control is contained in an INamingContainer-implemented object other than a page, such as a custom server control. If the naming container is a page, the value of the HtmlForm control's ID property is returned.

The UniqueID property and the Name property always return the same value. This is useful when the HtmlForm control is rendered on a browser that requires the HtmlForm control's UniqueID and Name properties to be the same. To keep these properties synchronized, the Name property always returns the value of the UniqueID property.

System_CAPS_noteNote

The name attribute is not an XHTML-compliant attribute and by default is not rendered by ASP.NET.

The following code example demonstrates how to use the UniqueID property to retrieve the unique identifier for an HtmlForm control.

<%@ page language="VB" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<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 xmlns="http://www.w3.org/1999/xhtml" >

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

    &nbsp    ;

    <asp:label id="Label2"
               runat="server">
    </asp:label>

  </form>

</body>

</html>

.NET Framework
Available since 1.1
Return to top
Show: