简体   繁体   中英

Use a RequiredFieldValidator in my webform

I used a requiredfieldvalidator in my webform application. I want when a person fills all of textboxes in my form and then press "OK" button, the data save to database. But if any textboxes didn't fill, requiredfieldvalidator show a message and data doesn't save to database. Now I can use requiredfieldvalidator and it messages me when textboxes didn't fill. But other data in my textboxes will save to my database. Please help me that in this condition, the data doesn't save to database. Thanks.

Validate your data on the server side (eg on the button click) before committing data to the database. Remember that if, for example, the user has disabled javascript in the browser, the validators will not work.

On the client side, you can use the ValidationGroup property.

  1. You can do a Page.IsValid before trying to save to the database.

  2. If you have used Validation Groups , make sure that you have properly used the validation groups for all the components.

It would be better to see some code though.

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