When target version is "ASP.NET 4.0", it follows different pattern while generating the client IDs. The new framework introduces the ClientIDMode property which can be used to set the way we want the client IDs to be generated. This is a very good decision from Microsoft to allow developers set what they want.
We have a standard pattern until ASP.NET 4.0, the algorithm for generating the id attribute from the ClientID property has been to concatenate the naming container (if any) with the ID, and in the case of repeated controls (as in data controls), to add a prefix and a sequential number. While this has always guaranteed that the IDs of controls in the page are unique, the algorithm has resulted in control IDs that were not predictable, and were therefore difficult to reference in client script.
This has its own pros and cons where we cannot predict the client IDs and the client IDs would be very long and sometimes considerably increases the page size for large pages.
These are the four values that can be set to this property
ClientIDMode property:
- AutoID – This is equivalent to the algorithm for generating ClientID property values that was used in earlier versions of ASP.NET. If you want the existing behavior as in previous versions set this property to "AutoID"
- Static – This specifies that the ClientID value will be the same as the ID without concatenating the IDs of parent naming containers. This can be useful in Web user controls. Because a Web user control can be located on different pages and in different container controls, it can be difficult to write client script for controls that use the AutoID algorithm because you cannot predict what the ID values will be.
- Predictable – This option is primarily for use in data controls that use repeating templates. It concatenates the ID properties of the control's naming containers, but generated ClientID values do not contain strings like "ctlxxx". This setting works in conjunction with the ClientIDRowSuffix property of the control. You set the ClientIDRowSuffix property to the name of a data field, and the value of that field is used as the suffix for the generated ClientID value. Typically you would use the primary key of a data record as the ClientIDRowSuffix value.
- Inherit – This setting is the default behavior for controls; it specifies that a control's ID generation is the same as its parent.
We can set this property at the page as well as control level, for more detailed information on this property please refer to the following link : http://www.asp.net/learn/whitepapers/aspnet4
We can set this property to "AutoID" to restore the behavior in the previous version.