I'm trying to performa an ajax validation for e-mail address. I need to know if user is already registered so I need to check it in my database. There is similar example: http://www.highoncoding.com/Articles/439_Performing_Instant_UserName_Availability_Check_Using_JQuery_Ajax_API.aspx
My current code is:
function validateEMail(email) {
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "ajax/services.asmx/validateEMail",
data: "{'email': '" + email + "'}",
dataType: "json",
success: function (result) {
$("#<%=lEMail.ClientID %>").html(result.d.result);
}
});
}
and server function:
public class EMailValidateResult
{
public bool valid { get; set; }
public string result { get; set; }
}
[WebMethod]
public EMailValidateResult validateEMail(string email)
{
EMailValidateResult result = new EMailValidateResult();
result.valid = false;
result.result = "<img src=\"icons/accept.png\" title=\"E-Mail is valid\" />";
return result;
}
I need to deny user page postback if the e-mail already exists.