One of the trickiest things that WebForms developers have to deal with is the management of HTML control identifiers by ASP.Net. In versions of ASP.Net prior to 4, the id attribute of an HTML control would always be generated at run-time and developers had little chance of guessing what the value would be If you were so lucky as to guess correctly, you would be able to properly reference your controls and life was good. If the structure of your page ever changed, ASP.Net would happily generate a new and different id for you. Now all of your client-side code is broken and that makes developers ANGRY!
"<%= txtFirstName.UniqueID %>"
"<%= txtFirstName.ClientID %>"
"<%= txtLastName.UniqueID %>"
"<%= txtLastName.ClientID %>"
clientId = controls.txtFirstName.ClientID;
I use this in many of my ASP.Net pages, especially pages that use AJAX controls that I want to make even more impressive for my end-users.
Is this a technique that you find useful? Write back in the comments area below to let me know what you think.