ValidationGroup指定后,ValidationSummary失效的解决办法。

1.没有指定ValidationGroup,ValidationSummmary正常运行。

 <div>
        <asp:ValidationSummary ID="valsStartUp" runat="server" DisplayMode="List"   />
    </div>
    <div>
        <div>
            <asp:TextBox runat="server" ID="txtCardNumber" MaxLength="19" />
            <asp:RequiredFieldValidator runat="server" ID="valrCardNumber" ControlToValidate="txtCardNumber"
                Display="none" ErrorMessage="* Card Number: required"   />
            <asp:RegularExpressionValidator ID="valeCardNumber" runat="server" ControlToValidate="txtCardNumber"
                ValidationExpression="\d{16,19}" ErrorMessage="* Cardnumber: Enter your full 16-19 digit card number"
                Display="None"  />
            <ajaxToolkit:FilteredTextBoxExtender ID="ftbeCardNumber" runat="server" TargetControlID="txtCardNumber"
                FilterType="Numbers" />
        </div> 
        <asp:Button ID="Button1" runat="server" Text="Button" />
  
       
    </div>

 2.指定validationGroup,ValidationSummary失效

 <div>
        <asp:ValidationSummary ID="valsStartUp" runat="server" DisplayMode="List" ValidationGroup="vagStartUp" />
    </div>
    <div>
        <div>
            <asp:TextBox runat="server" ID="txtCardNumber" MaxLength="19" />
            <asp:RequiredFieldValidator runat="server" ID="valrCardNumber" ControlToValidate="txtCardNumber"
                Display="none" ErrorMessage="* Card Number: required" ValidationGroup="vagStartUp" />
            <asp:RegularExpressionValidator ID="valeCardNumber" runat="server" ControlToValidate="txtCardNumber"
                ValidationExpression="\d{16,19}" ErrorMessage="* Cardnumber: Enter your full 16-19 digit card number"
                Display="None" ValidationGroup="vagStartUp" />
            <ajaxToolkit:FilteredTextBoxExtender ID="ftbeCardNumber" runat="server" TargetControlID="txtCardNumber"
                FilterType="Numbers" />
        </div> 
        <asp:Button ID="Button1" runat="server" Text="Button"/>
  
       
    </div>

 解决办法:<asp:Button ID="Button1" runat="server" Text="Button" ValidationGroup="vagStartUp" />

 

 

The default behaviour in ASP.NET is that when the user clicks a button that has no ValidationGroup specified (and has CausesValidation set to true), all validation controls that do not belong to a validation group are validated.

 

Therefore, to validate a specific group, you need to set the ValidationGroup property of the button that should cause the validation (and also possibly the CausesValidation property).

 

See the MSDN documentation for Button.ValidationGroup for details and an example.

 

posted on 2014-03-31 15:58  khh  阅读(520)  评论(0编辑  收藏  举报

导航