Jon Tackabury
Jon Tackabury

Reputation: 49249

ASP.NET enter key and form submit with no javascript

I have a form that I want to submit when the user presses the enter key. It works fine in Firefox, but not in IE. It is basically the same issue as this, except that I am not allowed to use any JavaScript: Enter button does not submit form (IE ONLY) ASP.NET

Unfortunately it looks like ASP.NET uses JavaScript to process the button postback. Is there a way around this issue that doesn't rely on JavaScript?

Upvotes: 1

Views: 3422

Answers (2)

Paulo Fagundes
Paulo Fagundes

Reputation: 1

My solution was this, a script that does click the login button.

Worked in all browsers!

public partial class Logon : UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        Page.ClientScript.RegisterClientScriptBlock(GetType(), "Logon", "document.getElementById('id_LoginButton').click();", true);
    }
}

Upvotes: 0

Mitchel Sellers
Mitchel Sellers

Reputation: 63126

The fix for this is what was listed in the bottom of the page of your linked post. IE needs to have an additional form field for some reason for this to work. I have used this in many projects, and it gets around the bug. Just add the following.

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

Upvotes: 4

Related Questions