asp.net form validation. Server-side or client-side
Here's (i think) an interesting question.
With AJAX more and more common i feel more and more like doing all form validation server-side.
Picture a registration form pre-AJAX. You have all your validation client-side using the common asp validation controls and validation summery...except...checking username availability, check emailadress availability, captcha and what not. So you end up with 2 kinds of validation and so presenting the user with 2 different UI's at 2 different moments. 2 words come to my mind. Ugly. Inconsistent.
So here's the question. Why not do all the validation server-side (开发者_如何学运维using AJAX or not).
(I'm not using JQuery yet, should i?)
codeka is correct. Client side validation prevents round trips to the server for simple errors.
Server-side is always required because you can't always assume client-side validation was correct.
Even with Ajax, I'd prefer to avoid the post to the server if the mistake was a simple typo. Personally, if your client-side and server-side validation results in a different error message being presented, then I think that's your problem, not the split between the two.
Having said that, there's no reason why you can't also do validation on the server-side with Ajax while you're entering your text. I've seen lots of forms that do a "username check" (for example) via Ajax as you type your requested name in.
精彩评论