I have an asp.net button with both onclick and onclientclick events.
<asp:Button ID="ButtonSave" Text="Save" ToolTip="Save" CssClass="causesValidation button" OnClick="ButtonSave_Click" OnClientClick="myfunction();" runat="server"/>
As soon as I click the button, both the client side and server side events are being fired. I only want the server side event to run if the client-side function succeeds.
I tried the following:
function myfunction()
{
// Show dialog
$('#mydialog').dialog('open');
// on dialog confirmation return true, else false;
}
<asp:Button ID="ButtonSave" Text="Save" ToolTip="Save" CssClass="causesValidation button" OnClick="ButtonSave_Click" OnClientClick="return myfunction();" runat="server"/>
Thank you
Change
OnClientClick="myfunction();"
by
OnClientClick="return myfunction();"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With