Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IE 8 - ASP.NET form not submitting when user presses enter key

I have a simple form written in asp.net/C# and when trying to hit enter while in the form's input box doesn't submit the form for some reason. I had implemented a fix for a previous bug where pressing enter would merely refresh the page without submitting the form data but now pressing enter just does nothing, the fix is below:

<div style="display: none">
    <input type="text" name="hiddenText" />
</div>

anybody know about a fix for this or a workaround?

like image 512
Jimmy Avatar asked Jan 18 '26 06:01

Jimmy


2 Answers

I'm assuming you have a button somewhere on your page, as well as an event handler for it.

Have you tried wrapping your form (with the button) inside a Panel control and setting the default button attribute?

i.e.

<asp:Panel id="pnlMyForm" runat="server" DefaultButton="btnMyButton">
<asp:textbox id="txtInput" runat="server" />
<asp:Button id="btnMyButton" text="Submit" runat="server" />
</asp:Panel>
like image 103
Kyle B. Avatar answered Jan 20 '26 21:01

Kyle B.


You can specify a default button for a form, which means hitting enter on any input control will fire that button (i.e. target the submit button). I haven't heard of this not working in any specific browser. This should eliminate your need for a workaround/hack.

<form id="form1" runat="server">
    <asp:Panel ID="pnlFormContents" runat="server" DefaultButton="btnSubmit">
        <!-- add some input controls as needed -->
        <asp:Button ID="btnSubmit" runat="server" Text="Submit" OnClick="btnSubmit_Click"/>
    </asp:Panel>
</form>

Hope this helps...

like image 35
KP. Avatar answered Jan 20 '26 19:01

KP.