Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / February 2006

Tip: Looking for answers? Try searching our database.

ASPX form submites twice with ENTER key

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
tanya - 16 Feb 2006 20:41 GMT
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 ) - 16 Feb 2006 21:52 GMT
see if this explains your problem

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

Signature

Regards

John Timney
Microsoft MVP

>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
[quoted text clipped - 11 lines]
>
> Thanks.
DWS - 17 Feb 2006 01:16 GMT
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.

> 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
[quoted text clipped - 11 lines]
>
> Thanks.
John Timney ( MVP ) - 17 Feb 2006 12:10 GMT
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

> Tanya,
> Check your button properties.  Buttons default to usesubmitbehavior=true
[quoted text clipped - 22 lines]
>>
>> Thanks.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.