Textbox OnEnter fires Button click

R

Rolly Ferolino

When pressing the Enter key on a textbox, the button click event is firing.
How can I prevent this from happening?
 
S

Steven Cheng[MSFT]

Hi Rolly,

Welcome to MSDN newsgroup.
Regarding on your description, the problem you met is due to a known issue
of the IE brower. When there are some entry fields and submit buttons on a
html page. If we hit "enter" key when the typing in the entry fields, the
page will always focus on the first submit button on that page and then
that submit is clicked and the page be submited. Here is a former thread
regarding on this problem, I've posted some workarounds there:

http://groups-beta.google.com/group/microsoft.public.dotnet.framework.aspnet
/browse_thread/thread/18c1ba6cd09ee4b3/280a5183137879d1?q=asp.net+prevent+%2
2enter%22+key+steven+cheng#280a5183137879d1

Also, there is an addtional means to do the trick, we can add a "hidden"
submit button which won't be submited forever at the beginning of the
<form> tag on that page, for example:

<form id="Form1" method="post" runat="server">

<input type="submit" style="WIDTH: 1px; HEIGHT: 1px" onclick="return
false">

<P>

<asp:TextBox id="TextBox1" runat="server"></asp:TextBox>
<asp:TextBox id="TextBox2" runat="server"></asp:TextBox></P>
<P>
<asp:Button id="Button1" runat="server" Text="Button"></asp:Button>
<asp:Button id="Button2" runat="server" Text="Button"></asp:Button></P>
</form>

This can also prevent the page from being auto submited when we hit "enter"
key .

HTH. Thanks,


Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 

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

Members online

No members online now.

Forum statistics

Threads
474,143
Messages
2,570,822
Members
47,368
Latest member
michaelsmithh

Latest Threads

Top