Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Validation in ASP.NET

Tags:

asp.net

What's the best way to validate controls, client-side JavaScript validation or server-side validation?

like image 613
Surya sasidhar Avatar asked Sep 06 '26 12:09

Surya sasidhar


1 Answers

As others have said, you should do both. Here's why:

Client Side

You want to validate input on the client side first because you can give better feedback to the average user. For example, if they enter an invalid email address and move to the next field, you can show an error message immediately. That way the user can correct every field before they submit the form.

If you only validate on the server, they have to submit the form, get an error message, and try to hunt down the problem.

Server Side

You want to validate on the server side because you can protect against the malicious user, who will probably know how to bypass your JavaScript and submit dangerous input to the server. The server should never trust input from the user, no matter what validation you've tried to do on the client side.

Server side validation is also important for compatibility - not all users will have JavaScript enabled.

Source JavaScript ClientSide vs. ServerSide Validation

like image 140
ACP Avatar answered Sep 08 '26 05:09

ACP



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!