使用atlas在客户端调用服务器端的方法:
1.在页面代码的方法上加'[WebMethod]'属性,例如:
[WebMethod]
public string HelloWorld(string s)
{
return s;
}
2.在aspx页面中添加 <atlas:ScriptManager runat="server" ID="ScriptManager1" />
<script type="text/javascript">
function CallPageMethod()
{
PageMethods.HelloWorld('test', OnRequestComplete);
}
function OnRequestComplete(args)
{
alert(args);//显示test
}
</script>
atlas框架会在页面产生一个PageMethods的代理,使用这个代理就可以直接访问页面代码中加了WebMethod属性的方法了.OnRequestComplete是方法完成后的回调,因为atlas访问页面后代码是异步的.
本文介绍如何使用Atlas框架实现客户端对服务器端方法的异步调用。具体步骤包括:1. 在服务器端方法上添加[WebMethod]属性;2. 在客户端页面中引入ScriptManager组件并定义PageMethods代理;3. 调用PageMethods中的方法,并设置回调函数处理返回结果。

126

被折叠的 条评论
为什么被折叠?



