asp.net ajax - 导致验证onBlur事件

时间:2011-07-18 08:08:52

标签: javascript asp.net ajax webforms

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

<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

1 个答案:

答案 0 :(得分:1)

您在CustomValidator中缺少EnableClientScript =“true”。不确定这是否是问题,因为我从未排除它。我回家后会试试。