Enter button does not submit form (IE ONLY) ASP.NET

I have a form with a textbox and a button. IE is the only browser that will not submit the form when Enter is pressed (works in FF, Opera, Safari, Chrome, etc.). I found this javascript function to try to coax IE into behaving; but no avail:

function checkEnter(e){
    var characterCode
    if (e && e.which) {
        e = e
        characterCode = e.which
    } else {
        e = event
        characterCode = e.keyCode
    if (characterCode == 13) {
        return false
    } else {
        return true

searchbox.Attributes("OnKeyUp") = "checkEnter(event)"

Any advice?

EDIT: This page on CodeProject outlines what Dillie was saying, and it works perfectly.


Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

Just create a text input in a hidden div on the page. This will circumvent the IE bug.

Example div:

    <!-- Fix for IE bug (One text input and submit, disables submit on pressing "Enter") -->
    <div style="display:none">
            <input type="text" name="hiddenText"/>

Method 2

The other thing I have done in the past is wrap the form area in a Panel and set the DefaultButton attribute to the submit button you have. This effectively maps the enter key to the submission as long as you have a form element in focus in the panel area.

Method 3

There is a good write up of this problem here, and a nice jquery based solution:


Method 4

// Use the following Javascript in your HTML view
// put it somewhere between <head> and </head>

    <script language="JavaScript" type="text/javascript"><!--
    function KeyDownHandler(btn)
      if (event.keyCode == 13)
        event.cancel = true;
    // -->

    // Put this in your TextBox(es) aka inside <asp:textbox ... >

Method 5

When using display:none, IE won’t see the button and therefore won’t be able to use it to submit the form. Instead, you could use z-index and absolute positioning to hide it under another element, e.g. with the style:

position:absolute; bottom: -20px; left: -20px; z-index: -1;

Now it’ll still be there, usable by IE, but hidden beneath another element.

Method 6

Hide the button – not using display:none, but with the following styles:

position: absolute; /* no longer takes up layout space */
visibility: hidden; /* no longer clickable / visible */

If you do this, you won’t need to add any other elements or hidden inputs.

Method 7

This is due to a peculiarity in IE for single text field inputs.

A simple solution is to stop the page having a single text field by adding another hidden one.

<input type="text" name="hidden" style="visibility:hidden;display:none;" />


Method 8

Does it use a GET instead of a POST? Is the URL too long? I’ve seen that…

Method 9

Basically, a form needs either a button, input type=”submit” or an input type=”image” to enable the builtin behaviour to submit a form on enter. You shouldn’t need a javascript to submit it.

All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Notify of

Inline Feedbacks
View all comments
Would love your thoughts, please comment.x