| 加入收藏| 设为首页| 联系我们
Asp.Net Ajax用JavaScript调用服务器端代码_Ajax教程_www.it958.cn
http://www.domcn.org 文章来源:本站收藏 点击数:
微软的Asp.Net Ajax框架使得实现AJAX功能变得非常的简单,但是在实际使用的过程中,还是可能会碰到很多的问题。今天,为了实现在用户焦点离开一个输入框的时候,能够从数据库查询相应的信息,并且填如相应的输入框中,就简单用了一下这个Ajax框架。碰到了不少问题,也Google了不少时间,才终于成功的运行起来了。首先,给输入框添加焦点失去的事件。我选择用OnBlur,不知道是不是最正确的,^_^。 Code highlighting produced by Actipro CodeHighlighter (freeware) http://www.CodeHighlighter.com/ -->1 onblur=javascript:CheckName()然后在CheckName中,获取输入的输入框的值,把它传到服务器端定义的事件中,并且定义回调事件 Code highlighting produced by Actipro CodeHighlighter (freeware) http://www.CodeHighlighter.com/ -->1 function CheckName()2 {3 var name = document.getElementById(xxx).value;4 PageMethods(name, CheckResult);5 }6 7 function CheckResult(result)8 {9 } Code highlighting produced by Actipro CodeHighlighter (freeware) http://www.CodeHighlighter.com/ -->1 [System.Web.Services.WebMethod]2 [System.Web.Script.Services.ScriptMethod]3 public static string GetLotInfo(string name)4 {5 // return something.6 }7 8 //在Asp.Net Ajax正式发布前,ScriptMethod的命名空间 为[Microsoft.Web.Script.Services.ScriptMethod]注:为了能引用System.Web.Script.Service.ScriptMethod, 需要引入System.Web.Extensions.dll