开发者

ValidationSummary doesn't show up

I have a few validation controls with a validationsummary. The client side validations shows up, after the user leaves the textbox for the validation. The server side validation shows never up. The Validationsummary shows never up.

What I am doing wrong?

                    <div class="designPhotoMiddleText" id="MiddleReg" >
                <asp:Panel DefaultButton="linkRegister" runat="server" ID="panRegister" >
                    Jetzt kostenlos registrieren:<br />
                    <br />

                    <table>
                        <tr>
                            <td style="width: 120px;">
                                Username:
                            </td>
                            <td>
                                <asp:TextBox ID="txtRegisterUsername" Width="150px" runat="server"></asp:TextBox>
                                <asp:CustomValidator ValidationGroup="Register" ID="valUsername" ControlToValidate="txtRegisterUsername"
                                 OnServerValidate="IsUsernameFree" CssClass="validator"
                                 runat="server" ErrorMessage="CustomValidator"></asp:CustomValidator>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                Passwort:
                            </td>
                            <td>
                                <asp:TextBox ID="txtRegisterPW1" Width="150px" TextMode="Password" runat="server"></asp:TextBox>
                                <asp:RegularExpressionValidator ValidationGroup="Register" CssClass="validator" ControlToValidate="txtRegisterPW1" ID="valPasswordLenght" runat="server" ErrorMessage="Das Passwort muss mindestens 6 Zeichen haben."></asp:RegularExpressionValidator>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                Passwort erneut:
                            </td>
                            <td>
                                <asp:TextBox ID="txtRegisterPW2" Width="150px" TextMode="Password" runat="server"></asp:TextBox>
                                <asp:CompareValidator CssClass="validator" ValidationGroup="Register"
                                    ID="valPW"  ControlToCompare="txtRegisterPW2" ControlToValidate="txtRegisterPW1" runat="server" ErrorMessage="Die eingegebenen Passwörter stimmen nicht überein."></asp:CompareValidator>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                Email:
                            </td>
                            <td>
                                <asp:TextBox ID="txtRegisterEmail" Width="150px" runat="server"></asp:TextBox>
                                <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." 
                                    Display="Dy开发者_开发知识库namic"></asp:RegularExpressionValidator>
                            </td>
                        </tr>   
                        <tr>
                            <td>
                            </td>
                            <td>
                                <asp:CheckBox ID="chkRegsiterAGBs" runat="server" />
                                <asp:HyperLink ID="linkAGB" Target="_blank" NavigateUrl="~/AGBs.aspx" runat="server">AGBs</asp:HyperLink> gelesen
                                <asp:CustomValidator ValidationGroup="Register" ID="valAGB" 
                                 OnServerValidate="IsAGBChecked" CssClass="validator"
                                 runat="server" ErrorMessage="CustomValidator"></asp:CustomValidator>
                            </td>
                        </tr>
                        <tr>
                            <td colspan="2">
                                <asp:LinkButton CausesValidation="true" ID="linkRegister" CssClass="linkWhite" runat="server" 
                                    onclick="linkRegister_Click">Jetzt Registrieren</asp:LinkButton>
                                <asp:ValidationSummary ValidationGroup="Register" ID="sumRegister" runat="server" 
                                HeaderText="Fehler:"
                                ShowSummary="true" DisplayMode="BulletList" />
                            </td>
                        </tr>
                    </table>
                    </asp:Panel>
                </div>



    public void IsUsernameFree(object source, ServerValidateEventArgs value)
    {
        string username = value.Value;
        DAL.User user = DAL.UserHandling.GetUserByName(username);
        value.IsValid = (user == null);
    }

    public void IsAGBChecked(object source, ServerValidateEventArgs value)
    {
        value.IsValid = (chkRegsiterAGBs.Checked);
    }


Can't tell for sure from looking at the code you've posted, but are you checking the Page's IsValid property anywhere? E.g. before running any other methods?

if (Page.IsValid){

    //Do additional processing
    //register user etc.
}

this check will force execution of all validation controls on the page and should then trigger the display of your validation errors.

EDIT:

You need to set the ValidationGroup to 'Register' in your markup that defines the linkRegister control

`<asp:LinkButton CausesValidation="true" ID="linkRegister" CssClass="linkWhite" runat="server" OnClick="linkRegister_Click" ValidationGroup="Register">Jetzt Registrieren</asp:LinkButton>`

Also, your RegularExpressionValidator for password needs to have its ValidationExpression property set in the markup:

`<asp:RegularExpressionValidator ValidationGroup="Register"
    CssClass="validator" ControlToValidate="txtRegisterPW1"
    ID="valPasswordLenght" runat="server" ErrorMessage="Das Passwort
    muss mindestens 6 Zeichen haben." Validationexpression="[\w+\d+]{6,}"
</asp:RegularExpressionValidator>`
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜