0

I have a form in asp.net page. Whenever enter key is pressed the page is posted back.

I don't have any submit button in my form and using javascript to submit form.

        <div class="row-fluid" align="center">
            <a id="saveConfirm" class="textDecorationNone">
                <div class="btn btn-primary">
                    <i class="icon-ok icon-white"></i>&nbsp;Add
                </div>
            </a>
            &nbsp;
                <asp:LinkButton ID="btnCancel" runat="server" Text="Cancel" CssClass="btn" CausesValidation="false" OnClick="btnCancel_Click">
                <i class="icon-remove"></i>&nbsp;Cancel
                </asp:LinkButton>
        </div>


row('#saveConfirm').click(function (){
    //submit form
});
Twix
  • 392
  • 1
  • 12
  • 38
  • Zero experience in ASP.net, googled `Enter causing postback even if no submit button is present` your title and the first response was: http://stackoverflow.com/questions/4209903/asp-net-page-enter-key-causing-post-back – Newd Jun 16 '15 at 13:03

2 Answers2

0

This can be addressed I believe with the accepted solution of the following post:

ASP.Net page enter key causing post back

Quoting:

  • You could set the DefaultButton on the Form or a Panel. This way you have full control what happens.
  • Set UseSubmitBehavior="False" on your Buttons. This disables the "AutoPostback" on Enter.

A possible javascript solution for ASP.NET is covered under this solution: Disable default button in ASP.NET [duplicate]

Community
  • 1
  • 1
samb0x
  • 185
  • 15
0

use Updated Panel which avoid postback while enter.

Srinivasa
  • 31
  • 1
  • 8