I would really like to use the jQuery validation plugin in an ASP.NET Web Forms application (not MVC).
I appreciate jQuery validation for a richer user interface. I can provide the end user, and I have some requirements to highlight invalid fields using the red border (css).
I evaluate asp.net validators because they run checks not only on the client, but also on the server, so I do not open various security vulnerabilities for any user who is smart enough to disable JavaScript in his browser.
So I'm looking for a nice clean way to integrate these two technologies.
The best I can come up with is to configure all ASP.NET validators for enableclientscript = false and repeat the validation rules on the client in jQuery and on the server as asp.net validators, but I already see some problems with this approach.
In the end, I found the lowest friction method for highlighting using asp.net validators, and jquery doesn't use the jQuery Validation plugin, but use a simple jquery string that follows (note that the exact syntax will depend on how you plan your forms) :
<script type='text/javascript'>
$("input[@type=submit]").click(function() {
$('span.validationerror:hidden').parent().parent().find('input').removeClass('inputError');
$('span.validationerror:visible').parent().parent().find('input').addClass('inputError');
});
</script>
source
share