0

我有 2 个 ASPxTextBox、ASPxValidationSummary 和 ASPxButton
在 JS 文件中有 OnPasswordValidation 函数
但是当我输入密码然后单击 Tab 按钮时,
txt_password 控件上的 SetIsValid(false) 不起作用但它适用于 txt_ConfirmPassword

为什么 ?

<dx:ASPxTextBox ID="txt_password" runat="server" Password="true" AssociatedControlID="txt_password">
    <ClientSideEvents Validation="OnPasswordValidation" />
</dx:ASPxTextBox>

<dx:ASPxTextBox ID="txt_ConfirmPassword" runat="server" Password="true" AssociatedControlID="txt_ConfirmPassword">
    <ClientSideEvents Validation="OnPasswordValidation" />
</dx:ASPxTextBox>

<dx:ASPxButton ID="btnSubmit" runat="server" Text="Submit" ClientInstanceName="btnSubmit" onclick="btnSubmit_Click" AutoPostBack="False">
<ClientSideEvents Click="function(s, e) {onClickBtnSubmit();}"/>
</dx:ASPxButton>

function OnPasswordValidation(s, e) {
    var objpassword = GetObj('txt_password');
    var objConfirmPassword = GetObj('txt_ConfirmPassword');
    var password = aspxGetControlCollection().Get(objpassword.id);
    var ConfirmPassword = aspxGetControlCollection().Get(objConfirmPassword.id);

    if (password.GetValue() == null) {
        password.SetIsValid(false);
        ConfirmPassword.SetIsValid(false);
        return;
    }
    if (ConfirmPassword.GetValue() == null) {
        password.SetIsValid(false);
        ConfirmPassword.SetIsValid(false);
        return;
    }
    if (password.GetValue().length > 5 || ConfirmPassword.GetValue().length > 5) {
        if (password.GetValue() == ConfirmPassword.GetValue()) {
            password.SetIsValid(true);
            ConfirmPassword.SetIsValid(true);
        }
        else {
            password.SetIsValid(false);
            ConfirmPassword.SetIsValid(false);
            password.SetErrorText = "Password must equal with Confirm Password";
            ConfirmPassword.SetErrorText = "Password must equal with Confirm Password";
        }
    }
    else {
        ConfirmPassword.SetIsValid(false);
        password.SetIsValid(false);
    }
}
4

1 回答 1

0

这不是实施验证的正确方法。这种方式OnPasswordValidation函数执行两次,每个文本框执行一次。
这是一张带有示例项目的票,应该可以满足您的需求: http: //www.devexpress.com/Support/Center/p/Q233058.aspx

我建议您阅读 DevExpress 控件验证概述,以了解如何在 devex 控件上实现验证。

于 2012-04-17T14:40:55.470 回答