Default Button / Press Enter Key in Web Form

Just notified by a new teammate today: There is page maintaining the master record of employees in one of my ASP.NET internal web app, he entered some text in that page and then press [ENTER], nothing happened so he came to me and told me that the search function is not work.

I go to that page and find that the reason of the "failure" is just because the programmer who wrote this page didn't handle the "Enter" key event, so nothing happen by the keyboard but only response from the "click" action. Ahh... What the...


Anyway, I went to Mike's blog immediately as I remembered he blogged about this topic in the past, I added his code by following his code snippet but it didn't work. (FYI: I have only 1 TextBox and 1 Button on that page only)

Finally, I added few lines of JavaScript code in order to catch this action (the keypoint is this line of code: event.returnValue=false;) and then it worked perfectly! Minor issue but "resume" the functionality. :o)

Colt Kwong

28 Comments

Comments have been disabled for this content.