Export (0) Print
Expand All

Control.ClientID Property

Gets the server control identifier generated by ASP.NET.

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

Property Value

The server control identifier generated by ASP.NET.

Remarks

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.

Example

[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

[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);
       }
 }

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

Requirements

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

Show:
© 2014 Microsoft