Monday, May 20, 2024
Homepage · c#
 Popular · Latest · Hot · Upcoming
167
rated 0 times [  168] [ 1]  / answers: 1 / hits: 19122  / 15 Years ago, sat, december 19, 2009, 12:00:00

I have a form where users scan in a barcode, the barcode reader automatically enters a carriage return in the value causing the form to submit since the browser chooses the first button as the default. How can I disable anything from happening when the enter key is pressed when entring a value in that textbox?


More From » c#

 Answers
55

You'll need to do it with javascript. In your markup for the text box, add an onkeydown handler like so:



<asp:TextBox ID=TextBox1 runat=server
onkeydown = return (event.keyCode!=13); >
</asp:TextBox>


This will return false if the key was the enter key, which will cancel the form submission.


[#98031] Wednesday, December 16, 2009, 15 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
cruzs

Total Points: 710
Total Questions: 113
Total Answers: 100

Location: Nepal
Member since Sat, Jul 18, 2020
4 Years ago
cruzs questions
Thu, Nov 26, 20, 00:00, 4 Years ago
Wed, Oct 28, 20, 00:00, 4 Years ago
Wed, Aug 19, 20, 00:00, 4 Years ago
Sun, Aug 2, 20, 00:00, 4 Years ago
;