views:

218

answers:

2

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?)

+2  A: 

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.

Dean Harding
You mean to present the server-side validation results in the same way as the validation summary does.Actually i don't like the limited layout options of the validation summary. In fact i would like to present the client-side validation results the same way i present the server-side validation results but the validation summary is not flexible enough
Jeroen
Ah, that's a good point, yes. I've usually forsaken the built-in ASP.NET validation controls for just this reason and always built my own with jQuery. It's a little more work, but a lot more flexible.
Dean Harding
+2  A: 

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.

Alan