微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

c# – 在文本框中输入值之前出现确认密码消息

我在asp.net c#application的aspx页面中编写了以下代码

<section>
      <label>
         <asp:Label ID="lblPassword" runat="server" Text="Password *"></asp:Label></label>
      <label class="input">

                <asp:TextBox ID="txtPassword" TextMode="Password" runat="server" data-content="Please Enter Your Password?" data-rel="popover" data-original-title="Password"></asp:TextBox>
                <asp:requiredFieldValidator ID="rfvPassword" runat="server" display="Dynamic" CssClass="state-error" ValidationGroup="profile" SetFocusOnError="true"
                    ControlTovalidate="txtPassword">please enter password</asp:requiredFieldValidator>
            </label>
        </section>

        <section>
            <label>
                <asp:Label ID="lblConfirmPassword" runat="server" Text="Confirm Password *"></asp:Label></label>
            <label class="input">

                <asp:TextBox ID="txtConfrimPassword" TextMode="Password" runat="server" data-content="Please Confirm Your Password?" data-rel="popover" data-original-title="Confrim Password"></asp:TextBox>
                <asp:requiredFieldValidator ID="requiredFieldValidator1" runat="server" display="Dynamic" ValidationGroup="profile" SetFocusOnError="true"
                    CssClass="state-error" ControlTovalidate="txtConfrimPassword">Please re-enter your password</asp:requiredFieldValidator>
                <asp:CompareValidator runat="server" ID="valComPassword" CssClass="state-error" ControlTovalidate="txtPassword" ControlToCompare="txtConfrimPassword"
                    display="Dynamic" ValidationGroup="profile" SetFocusOnError="true" ErrorMessage="Confirm password does not match"></asp:CompareValidator>
            </label>
        </section>

现在问题是当用户在txtPassword文本框中键入其密码时,验证(确认密码)将显示在txtConfirmPassword文本框下方.我希望用户在txtConfirm文本框中输入错误密码后会显示.

解决方法

当您将属性ControlToCompare设置为txtConfrimPassword并开始键入txtPassword文本框时,此验证将失败,因为当您键入txtPassword文本框时,确认密码文本框为空.

因此,您只需验证密码文本框而不是确认文本框.

<asp:CompareValidator runat="server" ID="valComPassword"  CssClass="state-error"  
    ControlTovalidate="txtConfrimPassword" ControlToCompare="txtPassword" 
    display="Dynamic" ValidationGroup="profile" SetFocusOnError="true" 
    ErrorMessage="Confirm password does not match">
</asp:CompareValidator>

这不会抛出错误消息,直到您开始输入txtConfrimPassword文本框,这很好.

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐