Stopping onclick from firing when onclientclick is false?
You want to add return
inside OnClientClick after a function is called. Otherwise, the button will post back even if function returns false.
<asp:button ID="Button1" runat="server" OnClick="Button1_Click" OnClientClick="return checkValidation()" Text="Submit" /><script type="text/javascript"> function checkValidation() { return confirm('Everything ok?'); }</script>
Sure. If you use return false
within your OnClientClick
it will prevent any navigation from happening. So you're code would look like:
<asp:LinkButton runat="server" OnClientClick="if(!ValidatePage()) { return false;}" />
Yes you can, In onclientClick function call use preventDefault()
function onclientClickFun(e){ if(!IsValidationSuccess) { e.preventDefault(); }}
OR
function onclientClickFun(e){ if(!IsValidationSuccess) { return false; }}