简体   繁体   English

ASP.NET验证规则可以属于多个组吗?

[英]Can an ASP.NET Validation Rule belong to multiple groups?

Is it possible for an ASP.NET Validation Rule to belong to multiple groups? ASP.NET验证规则是否可以属于多个组? I'd like to validate the same control in different ways based on what mode the form is in using a single Validator. 我想根据表单使用单个Validator的方式,以不同的方式验证同一控件。

For the purposes of this question, the modes are Simple, which requires fewer fields, or Complex, which requires more fields. 出于此问题的目的,模式是“简单”(需要较少的字段)或“复杂”(需要更多的字段)。 I know I can write CustomValidators (which I have done in the past), but I'd like a simpler solution. 我知道我可以编写CustomValidators(我过去做过),但是我想要一个更简单的解决方案。

So, I'd like to combine the following: 因此,我想结合以下几点:

<asp:RequiredFieldValidator ValidationGroup="Simple" ControlToValidate="Name" />
<asp:RequiredFieldValidator ValidationGroup="Complex" ControlToValidate="Name" />

Thanks! 谢谢!

No, unfortunately they cannot. 不,不幸的是他们不能。 But to my understanding your page is never shown in simple and complex mode at the same time, so maybe you should just add the validator from codebehind and set the validationgroup based on the current mode. 但是据我所知,您的页面永远不会同时在简单和复杂模式下显示,因此也许您应该仅从代码隐藏处添加验证器,并根据当前模式设置验证组。

不支持ASP.NET验证程序中的验证程序或按钮上的多个验证组

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

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