This documentation is archived and is not being maintained.

HtmlForm.UniqueID Property

Gets the unique programmatic identifier assigned to the HtmlForm control.

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

public override string UniqueID { get; }

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.


The name attribute is not an XHTML-compliant attribute and by default is not rendered by ASP.NET. For more information on configuring ASP.NET for non-XHTML rendering, see How to: Configure XHTML Rendering in ASP.NET Web Sites.

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

<%@ page language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
<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 + ".";


<html xmlns="" >


    <title>HtmlForm UniqueID Property Example</title>



    <form id="Form1"

    <h3>HtmlForm UniqueID Property Example</h3>        

    <asp:button id="Button1"
                text="Get the form's UniqueID" 

    <asp:label id="Label1"

    <br />

    <asp:button id="Button2" 
                text="Get this button's UniqueID"


    <asp:label id="Label2"




Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0