I have a ASP.Net button control in my page:
I have JQuery click event for this button:
$(':button').click(function (e) {
if ($('input:checked').length == 0) {
alert("Please select at least one option.");
e.preventDefault();
return false;
}
});
The function is called when OK button is called. However the server side event handler is also called. What am I missing?
Is your form using an
<input type="submit">?The
$(':button')selector only selects<button>and<input type="button">elements.See api docs here.
If you want to stop the form submitting you are probably better doing:
This is better because it will also handle a submit triggered by the Enter key for example.