-1

I an using jQuery validation plugin in asp.net 4.0 application.

Click here to see plugin

I have two button on page 1)Submit 2)Cancel

When i click on Submit button this validate the form and show appropriate error message.

I used Cancel button to go back to previous page.

But now when i click on Cancel button it also show the error message.

I don't want to validate the form on Cancel button click.

How can we do that.

Thanks.

Sukhjeevan
  • 3,074
  • 9
  • 46
  • 89

2 Answers2

1

Without seeing your code, I would assume that your "Cancel" button is also input[type=submit]. Change it to input[type=button] instead, then handle it appropriately.

For example, your "Submit" button may look like this:

$(".selector").validate({
   submitHandler: function(form) {
       // do other stuff for a valid form
     form.submit();
   }
});

Whereas, your "Cancel" button is like:

$("#cancel").click(function() {
     history.back(); // or window.location.href = ...your link
   }
});
Alex R.
  • 4,664
  • 4
  • 30
  • 40
0

Without seeing markup, I'm assuming your Cancel button is actually another submit button, and you handle the redirect in the code-behind. If this is true, clicking the cancel button will also trigger the validation plugin, since it's listening for the onsubmit event. You have two options off the top of my head:

  1. Use a hyperlink rather than a button/input element. You'll have to either hard-code the URL, or set it in the code-behind during page load.
  2. Set the UseSubmitBehavior to false on your .aspx page, which should change the markup to something other than <input type="submit" />.
Tieson T.
  • 20,774
  • 6
  • 77
  • 92