Tavousi
Tavousi

Reputation: 15486

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.

Upvotes: 0

Views: 512

Answers (2)

Paolo Tedesco
Paolo Tedesco

Reputation: 57222

Validate your data on the server side (e.g. 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.

Upvotes: 2

Jude Cooray
Jude Cooray

Reputation: 19872

  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.

Upvotes: 1

Related Questions