简体   繁体   English

在我的网络表单中使用RequiredFieldValidator

[英]Use a RequiredFieldValidator in my webform

I used a requiredfieldvalidator in my webform application. 我在Webform应用程序中使用了requiredfieldvalidator。 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. 但是,如果没有填写任何文本框,则requiredfieldvalidator会显示一条消息,并且数据不会保存到数据库中。 Now I can use requiredfieldvalidator and it messages me when textboxes didn't fill. 现在,我可以使用requiredfieldvalidator,当文本框未填充时,它会向我发送消息。 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. 请记住,例如,如果用户禁用了浏览器中的javascript,则验证器将不起作用。

On the client side, you can use the ValidationGroup property. 在客户端,您可以使用ValidationGroup属性。

  1. You can do a Page.IsValid before trying to save to the database. 您可以在尝试保存到数据库之前执行Page.IsValid

  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. 最好还是看一些代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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