Tuesday, June 1, 2010

Validating whether email id was already used using jquery for ajax & c# at backend

we have seen many times when we are filling up any online form as soon as we entered our email id many sites at that times only prompts us whether that email id id already used or not using ajax.
Doing such task is very very easy through jquery

$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: yoururl+methodName,
data: "{'emailid':'"+emailidtoCheck+"'}",
dataType: "json",
async: false,
success: function(res)
{ alert('email is free');return true}
error: function(obj)
{ alert('email is already used');return false}
});

if method is wriiten on the same c# page then u only have to pass the page name and method name no need to write FQDN

At backend make one [webmethod]
grab the parameters check ur database,return true or false depending upon whether email id exists or not.

For this u also need to add jquery as a script


:)

No comments:

Post a Comment