1

look like this article. http://www.c-sharpcorner.com/UploadFile/cd7c2e/validate-form-on-click-of-anchor-using-jquery/ but in this not mentioned how to stop button click until error completed.

so when we click on submit click and error occurred and submit click is fired on c# code i want to stop when error is displayed

1
  • you can use onclientclick="return validateForm()" to stop the server side call, Is this what you want? Commented May 9, 2014 at 14:21

3 Answers 3

1

If Error Occurred, that means Validation failed. So, you should return false, so that it won't fire the Button Click Code Behind Event. Else return true, so that it goes to Code Behind Click Event after Validation is completed.

So, simply...

if(Validation failed)
{
    return false;
}
else
{
    return true;
}
Sign up to request clarification or add additional context in comments.

Comments

1

Try something like this, prevent default behavior and submit form with js after validation:

<form action="actionpage.asp" onsubmit="submitForm();" name="form">

<input type="submit" value="Submit">

</form> 


function submitForm(){

    if(validationfails){

        return false;
    }
    else  {
        document.form.submit();
        return true;
    }
 }

Comments

1

To stop the default button behaviour (i.e. submitting the form) from firing straight away you need to return false at the end of your button click handler

e.g.

$("#mybutton").click(function() {

    // validate your form 
    $("#form1").validate({
            submitHandler: function (form) {
                form.submit();
            },
            rules: {
                name: "required",
                email: {
                    required: true,
                    email: true
                },
                field: {
                    required: true,
                    digits:true
                }
            }
        });

    return false;
});

Obviously the validation rules you create will depend on your form

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.