I have a registration page with the bootstrap
styling. I have <asp:RequiredFieldValidator>
and <asp:RegularExpressionValidator>
to validate the form.
Now i want to change the style if the validation fails and it should change back to normal when the validation is successful .
I have found a couple of answers like : txtBox.CssClass += "error_class" ;
.
But i want to know how can it be done the exact way. I found a script which did change CSS based on failed validation ,but upon successful validation it did not change to original CSS .
original css class of textbox : form-control
What will be the easiest way to do this , like setting border-color to red...??
P.S. : In the bootstrap template i am using , there are two fields : id
and class
. Here :
class : form-control
id : inputError
Current method to change class :
<script type="text/javascript">
function BtnClick() {
var val = Page_ClientValidate();
if (!val) {
var i = 0;
for (; i < Page_Validators.length; i++) {
if (!Page_Validators[i].isvalid) {
$("#" + Page_Validators[i].controltovalidate).css("border-color", "red");
}
}
}
return val;
}
</script>