我想检查是否存在登录而没有回发。

<script type="text/javascript">
    //validation login exists
        function ValidateLoginExists(source, args) {
            var exists;
            $.ajax({
                type: "POST",
                contentType: "application/json; charset=utf-8",
                url: '/account/userRegister.aspx/LoginExists',
                data: "{'login': '" + args.Value + "'}",
                dataType: "json",
                async: false,
                success: function (result) {
                    exists = result.d;
                }

            });

            args.IsValid = !exists;
        }
</script>

<div>
 <b>Login</b>
 <uc:TextBox ID="txtLogin" runat="server"
   onBlur="ValidateLoginExists(null,  $('#<%=txtLogin.ClientID %>').val())" />

  <asp:CustomValidator runat="server"
    ID="cvLoginValidator"
    ClientValidationFunction="ValidateLoginExists"
    ForeColor="Red" ErrorMessage="Login also exists"
    ControlToValidate="txtLogin" />
</div>


此代码仅适用于表单提交,而不适用于onBlur。如何在onBlur事件中调用ValidateLoginExists

最佳答案

您在CustomValidator中缺少EnableClientScript =“ true”。不知道这是否是问题,因为我从未排除过它。我到家后会尝试的。

关于javascript - asp.net ajax-导致验证onBlur事件,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/6730173/

10-13 06:11