开发者

Why Validator show in Validator and Validator Summary

开发者 https://www.devze.com 2023-01-29 22:59 出处:网络
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.

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 S开发者_开发技巧ie 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号