简体   繁体   中英

server side validation in asp.net

In asp.net, we have validations for textboxes but these validations are client side using javascript. If a user disables javascript in their browser and visit my website, validations will not work.

Does anybody have another idea?

You are correct in the fact that you cannot rely on client side validation alone. Personally I would invest my time into a one size fits all solution. I really like Data Annotations as it will perform the server side validation as well as automatically generate the client side as well. Very configurable and implemented bu simply adding attributes to your classes.

This is where the Page.Validate method and more importantly, the Page.IsValid property come in.

You can do server side something like this

 if (Page.IsValid)
 {
   // your code
 }

The Validate method is fired automatically by controls that have the CausesValidation property set to true.

Here is breif explanation of this.

Validation on the client side improves user experience (they get instant feedback on problem areas), but the validation on the server side is the one that really matters for keeping your data clean. You often need to do both types of validation in most cases.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM