ASPX form submites twice with ENTER key

T

tanya

I have a page with one form. I have one textbox in the page. I call a
client-side function on the OnKeyUp event of the textbox. This function
looks at the keycode of the keyup event on the textbox and checks for
13 which is the keycode for enter key. If I detect this keycode then I
do 2 things
(1) Set a hidden variable
(2) submit the form

I have noticed that the page is posted twice this way. But If I use a
button instead of detecting the enter key and submits the page that way
then the page is only posted once.

Please help.

Thanks.
 
G

Guest

Tanya,
Check your button properties. Buttons default to usesubmitbehavior=true so
there's your second submit. Set your button like this <asp:button
usesubmitbehavior="false"....></asp:button>

Good Luck
DWS

John Timney please review button behavior in the msdn library.
 
J

John Timney \( MVP \)

The link I provided explains the enter keys behaviour in different browsers
to help Tanya determine how using the enter key can affect submissions via
javascript and provides a working example of capturing and using the keycode
13 and ensuring that a certain button event if used is actioned, as opposed
to a different button/submit event pair bubbling postback events and causing
problems. Even the choice of button type can have an impact when your
capturing the keypress events when used in different browsers. Deactivating
autosubmit may indeed solve Tanya's immediate problem, it doesn't however
help her understand a connected range of problems she might expect when
capturing clientside keypress and how to work around them.

I dont think I need to review MSDN's behaviour on buttons - but thanks for
your enlightening suggestion.

Regards

John Timney
Microsoft MVP
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Toggle enter key 2
Enter Key in aspx page 2
trap enter key 0
Enter behaviour on textbox 2
enter key in textbox 4
Php modal form to email 1
postback when enter key? 3
Avoid Enter key during insert entry 1

Members online

No members online now.

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,812
Latest member
GracielaWa

Latest Threads

Top