我想检查登录是否存在而没有回发。
<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
?
答案 0 :(得分:1)
您在CustomValidator中缺少EnableClientScript =“true”。不确定这是否是问题,因为我从未排除它。我回家后会试试。