I have one form inside that form there are two buttons and two text box and after clicking first button validation appears for first textbox field after clicking second button validation of first textbox disappears but with post back .
How can I prevent post back while reseting jquery validation.
<form id="form1" runat="server">
<div id="div1" class="form-horizontal">
<div class="form-group">
<div class="col-md-3">
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
</div>
</div>
<div class="form-group">
<div class="col-md-3">
<asp:Button ID="Button1" CssClass="submit btn btn-primary " runat="server" Text="Submit" />
</div>
</div>
</div>
<div id="div2" class="form-horizontal">
<div class="form-group">
<div class="col-md-3">
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
</div>
</div>
<div class="form-group">
<div class="col-md-3">
<asp:Button ID="Button2" CssClass="btn btn-primary" runat="server" Text="Submit" />
</div>
</div>
</div>
</form>
<script>
$(document).ready(function () {
$('#Button1').click(function () {
$('#form1').validate({
errorClass: 'help-block animation-slideDown',
errorElement: 'div',
errorPlacement: function (error, e) {
e.parents('.form-group > div').append(error);
},
highlight: function (e) {
$(e).closest('.form-group').removeClass('has-success has-error').addClass('has-error');
$(e).closest('.help-block').remove();
},
success: function (e) {
e.closest('.form-group').removeClass('has-success has-error');
e.closest('.help-block').remove();
},
rules: {
'TextBox1': {
required: true,
},
},
messages: {
'TextBox1': {
required: 'ProvideYourCurrentPassword',
},
},
});
$("#TextBox2").rules('remove');
});
$('#Button2').click(function () {
$('#form1').validate({
errorClass: 'help-block animation-slideDown',
errorElement: 'div',
errorPlacement: function (error, e) {
e.parents('.form-group > div').append(error);
},
highlight: function (e) {
$(e).closest('.form-group').removeClass('has-success has-error').addClass('has-error');
$(e).closest('.help-block').remove();
},
success: function (e) {
e.closest('.form-group').removeClass('has-success has-error');
e.closest('.help-block').remove();
},
rules: {
'TextBox2': {
required: true,
},
},
messages: {
'TextBox2': {
required: 'ProvideYourCurrentPassword',
},
},
});
$("#TextBox1").rules('remove');
});
});
</script>
e.preventDefault()for eachbuttonand onceformvalidationis done based onvalidor not justsubmitthe form or keep it as it is..