I want to 开发者_开发问答check the entered email id already exists in my database or not. For that I need the Text box lost focus event so that I can call it in update panel trigger asynchronously. whereas in my event I can check whether the entered value exists in database or not.
I tried:
txtEmailId.Attributes.Add("onblur", "javascript:CheckEmailIdIsExist()");
If so, the what should be inside CheckEmailIdIsExist() javascript method? how to check database values asynchronously from javascript function?
look at using jQuery to make an AJAX call to a WebMethod on your site:
function CheckEmailIdIsExist(args) {
var loc = window.location.href;
loc = (loc.substr(loc.length - 1, 1) == "/") ? loc + "default.aspx" : loc;
$.ajax({
type: "POST",
url: loc + "/" + IsUniqueEmailAddress,
data: "{" + args + "}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: onSuccess,
fail: onFail
});
}
This would be on your server:
[WebMethod]
public static bool IsUniqueEmailAddress(string emailAddress)
{
// do some processing here
return true;
}
I think you will need to modify how you call the JavaScript function because you will need to pass the value of the control onblur="javascript:CheckEmailIdIsExist(this.value);"
Either use a javascript web service proxy, by adding a ServiceReference to your ScriptManager
http://www.semenoff.dk/en/Code-Corner/ASP.Net.AJAX/WebService-From-JavaScript.aspx
Alternatively use JQuery's ajax method:
http://api.jquery.com/jQuery.ajax/
The URL parameter can just be an httphandler, which takes the email address as a querystring parameter, checks the database and returns a result
Well, you should create an XMLRequest to some script which should reside on the server-side. The script itself should return some value and based on it you can make a decision whether the "emailId" exists within your database or not.
Note, that the XMLRequest is the method used for ajax calls. From this point I think you should read about ajax. If you use some library (ex jQuery) it might have it built in, so it will be very easy and straight forward for you to make some working implementation and verify your data :)
精彩评论