Click here to Skip to main content
15,884,537 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
For the 2 lines of code below after clicking a RETURN or TAB key:
JavaScript
document.getElementById('<%=txtPID.ClientID%>').focus();  //#1
document.getElementById('<%=txtPID%>').focus();           //#2

For #1, I can retrieve the control's values, but the control is not focus, and the highlight point flashes on the next control.
For #2, I got
JavaScript
JavaScript runtime error: Unable to get property 'focus' of undefined or null reference

What's wrong in my coding? Thanks.
Posted
Comments
Sergey Alexandrovich Kryukov 17-Aug-15 12:08pm    
And..?
Read page source on client side, and you will see.
—SA
s yu 17-Aug-15 12:16pm    
Thanks for your response. However, I am not clear your meaning. E.g. how to read page source on client side? For #1, it moves to another control rather than still focus on the current control; for #2, it pops up error. Could you hint me how to 'Read page source on client side'? Thanks again.
Zoltán Zörgő 17-Aug-15 13:26pm    
Just a question: why do you want to focus the element to read any property of it?
Sergey Alexandrovich Kryukov 17-Aug-15 13:51pm    
The argument of this function is the value of the attribute "id" of any HTML element. ClientID is one of the way to calculate this value on server side.
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900