document.getElementById(‘ControId’) function, you’d get the error message "object expected" or "object is null;" so why we get those errors while we are sure that the control’s ID and the JavaScript syntax are correct?! Well, the server controls’ IDs are changed in runtime, and they are concatenated with a prefix which is their content place holder, which in our case it would be the content of the master page and you can be sure from this if you run any page and view it’s source HTML using IE, try to search for any server control’s ID, you will find that it’s completely different from the one in the aspx file, so you have two choices in order to reference these controls correctly:that is using the encoding techniques to get the new generated ID programmatically; any asp server control contains a property called ClientID which provide us with the new generated ID for the control at run time, but we want to get this ID in the JavaScript code; so all we’ve to do is doing that:
var <variable name> = document.getElementById('<%=<controlId>.ClientID%>'); The symbols: <%=%>means that you can write any C# code inside them, so this way is very easy and flexible for anybody.
for Ex.
var txtId= document.getElementById('<%=txtId.ClientID%>');