必需+定期验证

时间:2009-11-24 11:05:38

标签: asp.net

 <asp:TextBox ID="Textboxtotalamount" 
     OnTextChanged="AmountChanged" 
     Width="90px" 
     AutoPostBack="true" 
     runat="server"></asp:TextBox>

 <asp:RequiredFieldValidator ID="RequiredFieldValidator" 
     runat="server" 
     ControlToValidate="Textboxtotalamount" 
     SetFocusOnError="True" 
     ValidationGroup="val">*</asp:RequiredFieldValidator>

 <asp:RegularExpressionValidator ID="RegularExpressionValidator1" 
     runat="server" 
     ControlToValidate="Textboxtotalamount" 
     ValidationExpression="^[-+]?[1-9]\d{0,13}(\.\d{1,3})?%?$" 
     SetFocusOnError="True">F</asp:RegularExpressionValidator>

在上面的代码中可以正确验证.......但在文本框中我调用“OnTextChanged” 事件....假如我在文本框中键入(字符)errormesge同时显示ontextchanged事件也称为母鸡错误发生....我已经停止OnTextChanged事件时,regularrexpression提出...... 请帮忙

1 个答案:

答案 0 :(得分:0)

试试这个

<asp:TextBox ID="Textboxtotalamount" OnTextChanged="AmountChanged" Width="90px" AutoPostBack="true"
            CausesValidation="true" ValidationGroup="val" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator" runat="server" ControlToValidate="Textboxtotalamount"
            SetFocusOnError="True" ValidationGroup="val">*</asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ControlToValidate="Textboxtotalamount" ValidationGroup="val"
            ValidationExpression="^[-+]?[1-9]\d{0,13}(\.\d{1,3})?%?$" SetFocusOnError="True">F</asp:RegularExpressionValidator>

我补充说。对于TextBox,CausesValidation =“true”和ValidationGroup =“val”。

和ValidationGroup =“val”到RegularExpressionValidator

现在只有当“val”组中的所有验证器都成功时,OnTextChanged才会触发