I am checking that if email exist or not using javascript , But it is firing "Email already exist" every time even if email does not already exist. Code is given below :
Javascript code :
function chkemailExist(source, args) {
var exists;
$.ajax({
type: "POST",
url: "Register.aspx/DoesUserExist",
data: "{'emailid': '" + args.Value + "'}",
contentType: "application/json; charset=utf-8",
dataType: "json",
async: false,
success: function (result) {
exists = result.d;
}
});
args.IsValid = exists;
if (!exists) {
var message="Email already exist for" + args.Value + ". ";
alert(message);
}
else { document.getElementById('ContentPlaceHolder1_CustomValidator1').innerHTML = ""; }
}
Web Method :
[WebMethod]
public static bool DoesUserExist(string emailid)
{
Boolean flg = true;
//Int32 cntchk = 0;
PAL_Register reg = new PAL_Register();
BAL_Register bal_reg = new BAL_Register();
reg.UserName = emailid;
flg = bal_reg.checkusername(reg);
return flg;
}
Please help to get correct my code so it fire alert for exist email only when email already exist in actual.