Javascript – Are validation server controls better than javascript in any way

asp.netjavascriptvalidation-controls

Are validation server controls better than javascript in any way ? Do they restrict us as we are only able to use the functionality that is provided by them. Please help me on this. I read about validation server controls on my own blog

Best Answer

It's best to use validation on both the client and the server:

  • Validating on the client gives instant feedback without constant roundtrips to the server. This makes for a better user experience.
  • Validating on the server is required to make sure you don't get bad data. After all, a malicious user could easily post data to your server without going through your client-side validation.

Now, as for how you implement that validation - if built-in "toolkit" controls perform appropriate validation for you, that's obviously going to be simpler than writing your own validation code. ASP.NET validators do both client- and server-side validation for you. From the docs for BaseValidator:

Validation controls always validate the associated input control on the server. Validation controls also have complete client-side implementation that allows script-enabled browsers (such as Microsoft Internet Explorer version 4.0 and later) to perform validation on the client. Client-side validation enhances the validation process by checking user input before it is sent to the server. This allows errors to be detected on the client before the form is submitted, avoiding the round trip of information necessary for server-side validation.