简体   繁体   中英

Why Validator show in Validator and Validator Summary

I have a validator and a validationsummery on my page.

When it happens, that the page is not valid, the text appears on the validator itself and in the validation summary.

What do im wrong?

 <asp:RegularExpressionValidator ValidationGroup="Register" CssClass="validator" ForeColor="black" 
                                    ControlToValidate="txtRegisterEmail" ID="valMail" runat="server" 
                                    ValidationExpression=".*@.*\.(com|net|org|edu|mil|at?|de?|ch?|uk?)$" 
                                    ErrorMessage="Bitte geben Sie eine gültige EMail-Adresse ein." 
                                     EnableClientScript="false" 
                                    Display="Dynamic"></asp:RegularExpressionValidator>


 <asp:LinkButton CausesValidation="true" ValidationGroup="Register" ID="linkRegister" CssClass="linkWhite" runat="server" 
                                    onclick="linkRegister_Click">Jetzt Registrieren</asp:LinkButton><br />
                                    <br />
                                <asp:ValidationSummary ValidationGroup="Register" ID="sumRegister" runat="server" 
                                HeaderText="Folgende Fehler sind aufgetreten:"  CssClass="validator" 
                                ShowSummary="true" DisplayMode="BulletList" />

That's by design, you're not doing anything wrong.

If you want the validation message to appear only in the summary, you can set the Display property of your validator control to None .

If you don't want the message to appear in the summary, you can use the ValidationGroup property to give different validation group names to your ValidationSummary control and your validator control.

If you do this (notice the asterisk after the "dynamic"> ):

<asp:RegularExpressionValidator 
    ValidationGroup="Register" CssClass="validator" ForeColor="black" 
    ControlToValidate="txtRegisterEmail" ID="valMail" runat="server" 
    ValidationExpression=".*@.*\.(com|net|org|edu|mil|at?|de?|ch?|uk?)$" 
    ErrorMessage="Bitte geben Sie eine gültige EMail-Adresse ein." 
    EnableClientScript="false" 
    Display="Dynamic">*</asp:RegularExpressionValidator>

You will get a little asterisk next any invalid fields, and then the error message will appear in the validation summary. In my apps I find it helpful to tag the fields with a little (red) asterisk, and then have the user look 'below', or wherever you summary is, for the list of validation errors.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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