I just want to add some client side (JQuery Javascript) validation in a web user control. I put an OnClientClick handler and the function gets called. BUT, even if I return
Try changing it to
OnClientClick="ValidateMail(); return false;"
Do you have a click event handler (registered via jquery) which returns true
? In that case, the return value of OnClientClick
is ignored.
Have a look at my question (and answer): Why doesn't returning false from OnClientClick cancel the postback
for some reason, although I didn't have any jquery event handlers attached, it didn't work.
What actually worked was:
OnClientClick="if (validate_form() == false) return(false);"
oddly enough this worked for me:
OnClientClick="javascript:SubmitTableData(); return CanSubmit();"
set the return value submit with the first function call:
function CanSubmit() {
return submit;
}
Hope this helps someone.
Just add javascript:
Example:
javascript:return ValidateMail();
Great answers. I do it this way. Same result- the OnClick event is not fired off if false is returned from Java function.
OnClientClick = "if (!ValidateDelete()) return false;"
OnClick="btnDeleteSupplier_Click"