or in other words, ‘Making the Enter Key Your Bitch’.
For my most recent project I have been tasked with incorporating bar code scanners into my ASP.NET / C# application. Much easier said than done, especially when almost every bar code scanner comes pre-programmed to press the ‘Enter Key’ after each successful scan. This becomes a real pain in a details view when you need additional information after the scan and the damn form keeps getting submitted.
With the help of a friend, we came up with a method to not only stop the default action of the Enter Key, but also make the cursor go where I wanted it to go next.
Here I have a simple web form asking the user for a Part and Quantity (app is for inventory purposes). The session ID is calculated automagically, so the cursor is in the Part field on page load.
When the user scans the bar code, we want the cursor to move down to Quantity, not click the Submit button.
First thing we do is add the script source to our header. In my case, this is on my Master page.
Next, we add this little ditty into our ASP.NET page.