Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
ClientID Property

Control.ClientID Property

Gets the server control identifier generated by ASP.NET.

[Visual Basic]
Public Overridable ReadOnly Property ClientID As String
public virtual string ClientID {get;}
public: __property virtual String* get_ClientID();
public function get ClientID() : String;

Property Value

The server control identifier generated by ASP.NET.


ASP.NET automatically generates a ClientID for a server control regardless of whether you have specified an ID property for it or not. This property is used to identify a control for client-side operations, such as ECMAScript functions.

Any name you assign to a server control using the ID property overrides the value of this property.


[Visual Basic, C#] 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

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>");    
          Control   myControl = (Control) myEnumerator.Current;
          // Display the ClientID property 
          Response.Write("<br>The ClientID property of Control : " + myControl.ClientID);

[C++, JScript] No example is available for C++ or JScript. To view a Visual Basic or C# example, click the Language Filter button Language Filter in the upper-left corner of the page.


Platforms: Windows 2000, Windows XP Professional, Windows Server 2003 family

See Also

Control Class | Control Members | System.Web.UI Namespace | NamingContainer | ID | INamingContainer | Composition vs. Rendering

© 2015 Microsoft