Connecting Tech Pros Worldwide Forums | Help | Site Map

ASPX form submites twice with ENTER key

tanya
Guest
 
Posts: n/a
#1: Feb 16 '06
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.


John Timney \( MVP \)
Guest
 
Posts: n/a
#2: Feb 16 '06

re: ASPX form submites twice with ENTER key


see if this explains your problem

http://www.allasp.net/enterkey.aspx

--
Regards

John Timney
Microsoft MVP

"tanya" <amqazi@gmail.com> wrote in message
news:1140122461.588601.249590@g47g2000cwa.googlegr oups.com...[color=blue]
>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.
>[/color]


DWS
Guest
 
Posts: n/a
#3: Feb 17 '06

re: ASPX form submites twice with ENTER key


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.

"tanya" wrote:
[color=blue]
> 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.
>
>[/color]
John Timney \( MVP \)
Guest
 
Posts: n/a
#4: Feb 17 '06

re: ASPX form submites twice with ENTER key


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

"DWS" <DWS@discussions.microsoft.com> wrote in message
news:01848502-2882-44A8-9CCA-D6585D8F4855@microsoft.com...[color=blue]
> 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.
>
> "tanya" wrote:
>[color=green]
>> 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.
>>
>>[/color][/color]



Closed Thread