问题描述
我在页面上使用asp:requiredfieldvalidator.为控件关闭此功能的通常方法是设置
I'm using asp:requiredfieldvalidator on my page. The usual way of turning this off for a control is to set
CausesValidation="false"
但是,我不想进行验证的按钮多于我希望进行验证的按钮.
However I've got more buttons that I don't want to cause validation than I have that do want validation.
所以我的想法是,默认情况下将其关闭并在需要时将其打开会更容易,但我不知道如何.
So my thinking is that it would be easier to turn it off by default and on when I need it but I don't know how.
预先感谢
推荐答案
我认为您默认情况下无法将其关闭,但是您可以在要引起验证的按钮及其应验证的控件上设置ValidationGroup属性
I don't think you can turn it off by default, but you could set ValidationGroup property on the buttons you want to cause validation and the controls they should validate.
代码示例:
<asp:TextBox ID="tb1" runat="server" ValidationGroup="ValidateMe" />
<asp:TextBox ID="tb2" runat="server" />
<asp:RequiredFieldValidator" ID="rfv1" runat="server" ControlToValidate="tb1" ValidationGroup="ValidateMe" />
...
<asp:Button ID="btnSubmit" runat="server" ValidationGroup="ValidateMe" />
单击btnSubmit时,将仅验证tb1,而不受应用于tb2的任何其他验证控件的影响.
When btnSubmit is clicked, only tb1 will be validated, regardless of any other validation controls applied to tb2.
这篇关于默认情况下关闭ASP验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!