防止文本框触发验证器

时间:2013-05-07 10:31:44

标签: asp.net validation textbox

所以我有一个包含6个验证器的文本框。每种类型2,因为我有两个验证组,具体取决于用户点击的按钮。我的问题是每次文本框失去焦点时会显示两条错误消息,这看起来很奇怪。我已经尝试将文本框的CausesValidation属性设置为“false”但它不起作用。

Textbox&验证者 -

<asp:TextBox ID="collectionDtl_Qty" runat="server" CssClass="formText" 
 AutoPostBack="false" CausesValidation="false" Text="0">
</asp:TextBox>
<asp:FilteredTextBoxExtender ID="collectionDtl_Qty_Filtered" runat="server" 
 FilterMode="ValidChars" TargetControlID="collectionDtl_Qty" ValidChars="1234567890,">
</asp:FilteredTextBoxExtender>
<asp:CustomValidator ControlToValidate="collectionDtl_Qty" ID="collectionDtl_Qty_CValidator" 
 runat="server" ClientValidationFunction="coll_QtyValidator"
 Text="Quantity cannot be greater than requested quantity." ForeColor="Red" 
 ValidationGroup="formValidation" Display="Dynamic">
</asp:CustomValidator>
<asp:CustomValidator ControlToValidate="collectionDtl_Qty" ID="collectionDtl_Qty_CValidator2"
 runat="server" ClientValidationFunction="coll_QtyValidator"
 Text="Quantity cannot be greater than requested quantity." ForeColor="Red" 
 ValidationGroup="detailValidation" Display="Dynamic">
</asp:CustomValidator>
<asp:CompareValidator ControlToValidate="collectionDtl_Qty" ID="collectionDtl_Qty_Comparer" 
 runat="server" Text="Quantity must be greater than 0." ForeColor="Red" 
 ValidationGroup="formValidation" Display="Dynamic"
 ValueToCompare="0" Operator="GreaterThan" Type="Integer">
</asp:CompareValidator>
<asp:CompareValidator ControlToValidate="collectionDtl_Qty" ID="collectionDtl_Qty_Comparer2" 
 runat="server" Text="Quantity must be greater than 0." ForeColor="Red"
 ValidationGroup="detailValidation" Display="Dynamic"
 ValueToCompare="0" Operator="GreaterThan" Type="Integer">
</asp:CompareValidator>

任何帮助都将不胜感激。

1 个答案:

答案 0 :(得分:0)

嗨,根据你的问题。我明白你必须禁用验证器或使用基于按钮点击的验证。

  1. 对于按钮,请单击“使用ValidationGroup”

    =的ValidationGroup “保存”

  2. 如果你想在条件下禁用验证器。试试这个

    ValidatorEnable(document.getElementById('&lt;%= rqrgvddlCategory.ClientID%&gt;'),false);

    希望它会对你有所帮助。