javascripthtmlasp.netonclientclick

OnClientClick triggered when enter pressed in ASP.NET


I have a form with runat="server" and inside it I have two elements :

<form runat="server">
  <asp:Button runat="server" OnClientClick="doSomething();" />
  <asp:TextBox runat="server" Text="hello" />
</form>

My problem is when I press enter while the cursor inside the textbox the doSomething function runs. What can I do to prevent this?


Solution

  • set UseSubmitBehavior to false.

    <asp:Button runat="server" OnClientClick="doSomething();" UseSubmitBehavior="False" />