0

我的网页中有多个验证器(比较、必需、自定义)。当我单击提交按钮时,页面回发。但是,我为所有字段提供了相同的验证组。怎么了?

 <div class="innerUserName" style="margin-top: 0px;">
                                <asp:TextBox ID="txtUserName" runat="server" ClientIDMode="Static" 
                                    MaxLength="20" Style="margin-left: 28px;" Width="230" CausesValidation="True"></asp:TextBox>

                            </div>

 <asp:HiddenField ID="hdnField" runat="server" ClientIDMode="Static" />
                            <div id="divUserNameAvailability">
                            </div>
                            <asp:RequiredFieldValidator ID="reqval_UName" runat="server" ControlToValidate="txtUserName"
                                CssClass="validation" Display="Dynamic" ErrorMessage="Please Provide User Name"
                                SetFocusOnError="True" ValidationGroup="SignUp"></asp:RequiredFieldValidator>
                                <%--User Name Not Available--%>
                            <asp:CustomValidator ID="cusval_UName" runat="server" ErrorMessage="" ClientIDMode="Static"
                                ClientValidationFunction="ValidateUsername" ControlToValidate="txtUserName" CssClass="validation"
                                Display="Dynamic" SetFocusOnError="True" ValidationGroup="SignUp"></asp:CustomValidator>


<div class="innerPwd" style="margin-top: 0px;">
                                <asp:TextBox ID="txtPassword" runat="server" TextMode="Password" 
                                    Style="margin-left: 28px;" Width="230" CausesValidation="True"></asp:TextBox>
</div>

 <span>
                            <asp:RequiredFieldValidator ID="reqval_Pwd" runat="server" ControlToValidate="txtPassword"
                                SetFocusOnError="true" CssClass="validation" Display="Dynamic" ErrorMessage="Please Provide Password"
                                ValidationGroup="SignUp" />
                            <asp:RegularExpressionValidator ID="regexPassword" runat="server" ControlToValidate="txtPassword"
                                SetFocusOnError="true" Display="Dynamic" ErrorMessage="Please Provide Valid Password"
                                ValidationExpression="^(?=.*[0-9]+.*)(?=.*[a-zA-Z]+.*)[0-9a-zA-Z]{6,20}$" ValidationGroup="SignUp"
                                CssClass="validation"></asp:RegularExpressionValidator></span>
                        <div>



<asp:Button ID="btnSignUp" runat="server" Text="Create Account" Style="border: 0px;
                                    background-color: #396fd1; font-weight: bold; height: 29px; font-size: 12px;
                                    color: #fff3dd;" ValidationGroup="SignUp" />

功能:

function ValidateUsername(sender, args) {
            var div = document.getElementById("divUserNameAvailability");
            var img = document.getElementById("imgUserNameAvailability");

            if (div.style.display == "none") {
                CallMe("txtUserName");
            }

            if (div.style.display == "inline") {
                var imgFileName = getName(img.src);
                if (imgFileName == "wrong")
                    args.IsValid = false;
                else
                    args.IsValid = true;
            }
        }
4

0 回答 0