First there was the ASP.NET validators and we used them… Then some people on the team did things manually in javascript… Then a bunch of jquery validation libraries came out… Then MVC2 came out with attributes as validators..
I work with apps that have alot of forms with alot of various validation (Some fields needs to be compared with other values in a DB so a postball/ajax call is required) .. Right now I have a mess of ASP.NET custom validators and functions that calculate on the server side as well.
Can I get some opinions on the best tool/combination to approach this job that can create the smallest/most elegant code? Pure server side solution? AJAX/Jquery? A certain plugin for jquery?
For example, I have 2 dates.. I want to make sure that the 1st date is less than the 2nd date… Are there jquery validators that encapsulate this? My feeling is if I can get jquery plugins to handle half the more basic validation for my that could cut my code in half.
DynamicData for asp.net mvc and dynamic data.
On webforms I have only used the the asp.net validators approach. This doesn’t mean to go copy-pasting all over custom validations you may have i.e. you add your own custom validators as needed and only on very special circumstances you use extra validators hooked to methods+scripts on the page.
Depending on how you structure your code, I would expect to be able to leverage some of the infrastructure around DataAnnotations. I can’t give it for a fact, you know the usual issues on asp.net something usually tied up to implementation details, worth a shot if there aren’t better options.
Update 1:
a v. quick search gave: http://blogs.microsoft.co.il/blogs/gilf/archive/2010/04/08/building-asp-net-validator-using-data-annotations.aspx, which is rudimentary piece – but shows a way that you can leverage the data annotations on web forms (for the server side).
Update 2: another one with the same approach as above, but does both server & client side validation:
http://geeks.ms/blogs/rcarreras/archive/2010/04/20/validando-asp-net-web-form-con-dataannotation-en-ambos-lado-cliente-y-servidor.aspx. Again rudimentary, but certainly can be used as the basis to get a more complete automatic validation based on the annotations. Note: depending on what you use you can have the validators automatically added on the appropriate places, although I must warn that it might be tricky to get it to work well if you haven’t worked with dynamically added validators before