Updated on Kisan Patel
This tutorial will show you how to fire JavaScript function on button click and prevent the form submission.
First, specify the OnClientClick
event of the button and also add the UseSubmitBehavior=false
.
<asp:Button ID="btnSubmit" runat="server" UseSubmitBehavior="false" OnClientClick="return AlertFunction()" Text=" Show Alert and Do not submit the form " />
Next, add the javascript AlertFuntion()
as shown in below code:
<script language="javascript" type="text/javascript"> function AlertFunction() { alert("JavaScript function called"); return false; } </script>
It’s Done!