I am working on a registration page that is styled with bootstrap. The form validation is done using
<asp:RequiredFieldValidator>
and <asp:RegularExpressionValidator>
.
My goal now is to change the style of the form elements when validation fails, and revert back to the original style when validation is successful.
I have come across suggestions like adding an error class using
txtBox.CssClass += "error_class";
, but I am looking for a more precise solution. I came across a script that changes the CSS on failed validation, but it does not reset to the original CSS upon successful validation.
The original CSS class of the textbox is: form-control
What would be the easiest way to achieve this, like setting the 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>