Click to Rate and Give Feedback
MSDN
MSDN Library
.NET Development
.NET Framework
Control Class
 ClientID Property
This page is specific to
Microsoft Visual Studio 2008/.NET Framework 3.5

Other versions are also available for the following:
.NET Framework Class Library
Control..::.ClientID Property

Gets the server control identifier generated by ASP.NET.

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

Visual Basic (Declaration)
<BrowsableAttribute(False)> _
Public Overridable ReadOnly Property ClientID As String
Visual Basic (Usage)
Dim instance As Control
Dim value As String

value = instance.ClientID
C#
[BrowsableAttribute(false)]
public virtual string ClientID { get; }
Visual C++
[BrowsableAttribute(false)]
public:
virtual property String^ ClientID {
    String^ get ();
}
J#
/** @property */
/** @attribute BrowsableAttribute(false) */
public String get_ClientID()
JScript
public function get ClientID () : String

Property Value

Type: System..::.String

The server control identifier generated by ASP.NET.

Sometimes, it is not possible to assign a unique name to a control. For example, if a Repeater control contains a Label control in one of its templates, an instance of that Label control is rendered for each item in the Repeater control. To prevent naming conflicts when multiple instances of a control are rendered, ASP.NET automatically generates a unique ClientID value for each server control on a page. The ClientID value is generated by concatenating the ID value of the control and the UniqueID value of its parent control. If the ID value of the control is not specified, an automatically generated value is used. Each part of the generated ID is separated by an underscore character (_).

Note:

The ClientID value generated for a control is identical to the UniqueID value, except that an underscore character is used to delimit the ID values, instead of the character specified by the IdSeparator property. By default, the IdSeparator property is set to a colon character (:). Because the ClientID value does not contain colon characters, it can be used in ECMAScript, which does not support IDs containing colons.

The ClientID value is often used to programmatically access the HTML element rendered for a control in client-side script. For details, see Client Script in ASP.NET Web Pages.

The following example iterates through the ControlCollection object for a page and displays the ClientID property for each control contained by the page.

Visual Basic
Sub Page_Load(sender As Object, e As EventArgs)
   Response.Write("<h4>Control_ClientID Sample</h4>")
   ' Get the list of all controls.
   Dim myEnumerator As IEnumerator = Controls.GetEnumerator()
   Response.Write("<br />Enumerating Controls Collection<br />")
   While myEnumerator.MoveNext()
      Dim myControl As Control = CType(myEnumerator.Current, Control)
      ' Display the ClientID property.
      Response.Write("<br />The ClientID property of Control : " & myControl.ClientID)
   End While
End Sub

C#
void Page_Load(object sender,EventArgs e)
{
       Response.Write("<h4>Control_ClientID Sample</h4>");
       // Get the list of all controls.
      IEnumerator myEnumerator = Controls.GetEnumerator();
      Response.Write("<br />Enumerating Controls Collection<br />");    
      while(myEnumerator.MoveNext())
      {
          Control   myControl = (Control) myEnumerator.Current;
          // Display the ClientID property 
          Response.Write("<br />The ClientID property of Control : " + myControl.ClientID);
       }
 }

J#
void Page_Load(Object sender, EventArgs e) 
{
    get_Response().Write("<h4>Control_ClientID Sample</h4>");

    // Get the list of all controls.
    IEnumerator myEnumerator = get_Controls().GetEnumerator();
    get_Response().Write("<br />Enumerating Controls Collection<br />");
    while(myEnumerator.MoveNext()) {
  Control myControl = (Control)(myEnumerator.get_Current());
  // Display the ClientID property 
  get_Response().Write("<br />The ClientID property of Control : " 
      + myControl.get_ClientID());
    }
} //Page_Load

Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, 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 SP1, 3.0, 2.0 SP1, 2.0, 1.1, 1.0
Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content      
Processing
© 2008 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker