0

I have the following command button:

<asp:Button Text="Insert Value" UseSubmitBehavior="false" runat="server" OnClientClick="return Confirmation.value('insert');" CommandName="Insert" />

I am using UseSubmitBehavior="false" to prevent ASP.Net page enter key causing post back

I do not want to listen to the enter keyCode via javascript because enter is used to submit non-webform elements not related to the form

Apparently, when using a Command and UseSubmitBehavior="false" then OnClientClick doesnt work. If I turn on submit behavior it works as expected but then hitting enter on the page automatically tries to click the button.

I prefer not to listen for the click event in Jquery or in javascript, and prefer a webform solution. Possible a better way of prevent enter from submitting the form or a way for OnClientClick to work properly with no submit behavior

CuriousDeveloper
  • 849
  • 2
  • 8
  • 27

1 Answers1

0

You may need to use Panel and keep all your form inside Panel Tag and set the DefaultButton value of Panel to Button. Like Below:

    <asp:Panel ID="Panel1" runat="server" DefaultButton="Button1">

         // other form elements

       <asp:Button Text="Insert Value" ID="Button1" runat="server" OnClientClick="return Confirmation.value('insert');" />
    </asp:Panel>
Sonal Borkar
  • 531
  • 1
  • 6
  • 12