One way to access a control from client script is to pass the value of the ClientID property of the server control to the document.getElementById method. The ClientID property value is rendered in HTML as the id attribute. To use this method, you must know how the ClientID value is generated. This document explains the algorithms that are available and how to select one.
To access a control from client script
Add the control to a Web page or user control.
Set the ClientIDMode property of the control to one of the following values:
AutoID. Use this value when you already have client script that you want to use and the script assumes that ClientID values will be generated by using the algorithm that was used in the .NET Framework 3.5 and earlier versions. The value of the ClientID property is generated by concatenating the ClientID property of a control's parent naming container and the ID property of the control. When this algorithm is used in a data-binding scenario, an incrementing value is inserted after the ClientID value of the parent control and before the ID value of the control. Each segment is separated by an underscore (_).
The default value for a Web page is Predictable and the default value for a control in a page is Inherit. Therefore, if you do not set explicitly set the ClientIDMode property of the parent control or the page, a control will automatically inherit the Predictable setting. (There is an exception: for projects converted from ASP.NET 3.5, the default value is set to AutoID. For more information, see ASP.NET Web Server Control Identification.)
If you have set the ClientIDMode property to Predictable, set the ClientIDRowSuffix property to the name of the data field that you want to use to uniquely identify each instance of the control. For the GridView control, you can enter multiple field names separated by commas.
If you do not set the ClientIDRowSuffix property, ASP.NET uses a sequential number as the ClientID suffix. This is similar to the algorithm used for AutoID, except that the number is placed at the end of the generated ID instead of before the control's ID. In addition, the sequential number appears without a ctrl prefix (for example, the ClientID would be Container_Control_25 instead of Container_ctrl25_Control).
In client script, use the document.getElementById method and pass to it the ClientID value that will be generated by the algorithm you selected.
The following example shows a user control that contains a Label control with the ClientIDMode property set to Static. The user control also contains client script that accesses the control by its ID. Because the ClientIDMode property is set to Static, this user control can be used in any container control and have the same value for the ClientID property.