最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Javascript vs ASP.NET validation, which one to choose? - Stack Overflow

programmeradmin4浏览0评论

Concerning validation,

  1. Are javascript and ASP.NET validation used for the same purpose?

  2. If yes, which one do you remend? Please provide a simple explanation.

Thanks

Concerning validation,

  1. Are javascript and ASP.NET validation used for the same purpose?

  2. If yes, which one do you remend? Please provide a simple explanation.

Thanks

Share Improve this question edited May 20, 2010 at 3:16 Kelsey 47.7k16 gold badges127 silver badges162 bronze badges asked May 19, 2010 at 22:32 BartBart 4,92016 gold badges50 silver badges68 bronze badges 2
  • 7 Never trust the client – Daniel Vassallo Commented May 19, 2010 at 22:36
  • 4 JavaScript tutorial, lesson 1: JavaScript can be disabled. – BalusC Commented May 19, 2010 at 22:40
Add a ment  | 

5 Answers 5

Reset to default 15

Always validate on the server. Client-side validation is only to make the user experience more pleasant. Which is important, but only important as far as the experience goes. Validation on the client is not important at all for the purposes of validation, because anything running on the client machine can be promised or bypassed by the same client.

ASP.NET validation controls are the way to go if your using Webforms. It automatically does client side and server side validation. If you go with vanilla javascript you will be missing the most important part of the validation process which is server side validation.

Validation server side is really the only validation that you can perform reliably to ensure you have good data. Client side is there just to make the process a little more user friendly only.

There are so many built in validation controls in ASP.NET Webforms that it makes validation a lot easier and if you run into a case where you need something specific, just use an CustomValidator.

You should ALWAYS have server side validation. Javascript validation is nice, but it is not the same as server-side. You should always assume that the client will be able to send you malformed data.

I'm in...

You should ALWAYS validate on the server!

Do both

If you want something to 'happen' when the user does something 'valid' then validate it using some javascript before making a request back to the server (don't make a request unless it's needed).

Once the user has done something 'valid' then perform the request where you validate again on the server side since you 'never trust anyone'.

发布评论

评论列表(0)

  1. 暂无评论