asp.net 中的字段验证器

发布于 2024-09-01 23:52:33 字数 117 浏览 1 评论 0原文

是否可以使用“必填字段验证器”控件来验证多个字段(例如,我有 12 个必需的文本框。我想尝试避免使用 12 个 RFV 控件。如果确实触发了验证,有没有办法显示自定义消息(“textA 为空”或“textB 为空”)等?

Is it possible to have "Required Field Validator" controls to validate more than one field (example I have 12 textboxes that are required. I want to try an avoid having 12 RFV controls. If a validation does get triggered, is there a way to display a customized message ("textA is empty" or "textB is empty") etc.?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

万人眼中万个我 2024-09-08 23:52:33

您可以创建一个自定义验证器来验证所有控件。

http://msdn.microsoft.com/ en-us/library/system.web.ui.webcontrols.customvalidator.aspx

必填字段验证器一次只能验证一个控件。

You can create a custom validator that goes through validates all the controls.

http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.customvalidator.aspx

The Required Field Validator can only validate one control at a time.

も星光 2024-09-08 23:52:33

您不能使用 RequiredFieldValidator 来做到这一点;您可以编写自己的 CustomValidator 来执行此操作,但验证将在服务器端而不是客户端进行。

You cannot do that with a RequiredFieldValidator; you could write your own CustomValidator to do that, but the validation would be on the server side rather than on the client side.

冷默言语 2024-09-08 23:52:33

正如其他人所提到的,您可以创建可以在客户端和服务器端进行验证的 CustomValidator。您必须牢记以下几点。

1) 确保将您的客户端脚本公开为 Web 资源。这将使脚本能够被浏览器缓存。

2) 使用特定的属性来定位特定的文本框。这可以通过给它们一个特定的类来执行,该类将在您的自定义验证器控件中进行验证。

希望有帮助!

As mentioned by everyone else you can create your CustomValidator that can validate on the client side and on the server side. There are couple of things that you must keep in mind.

1) Make sure to expose your client script as a Web Resource. This will enable the script to be cached by the browser.

2) Use a certain attribute to target certain TextBoxes. This can be performed by giving them a certain class which will be validated in your Custom Validator control.

Hope it helps!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文