WEB2.0 中应用回调事件

来源:互联网 发布:淘宝熏香炉 编辑:程序博客网 时间:2024/06/11 19:29

所涉及到的函数有:

服务器端:

1、ClientScriptManager.GetCallbackEventReference 方法 (Control, String, String, String)

Control 可用this;string 从客户端传入值的参数,回调后作为参数值的返回载体;string  客户端js脚本函数的名字

此函数处理服务器端(成功)事件的结果;string  客户端处理程序上下文 如果 采用代码分离方式,当客户端接受

脚本函数体已经存在,可以为“”;

2、

public string GetCallbackEventReference (string target,string argument,string clientCallback,string context,string clientErrorCallback,bool useAsync)

参数

target

处理客户端回调的服务器 Control 的名称。该控件必须实现 ICallbackEventHandler 接口并提供 RaiseCallbackEvent 方法。

argument

从客户端脚本传递给服务器端的一个参数

RaiseCallbackEvent 方法。

clientCallback

一个客户端事件处理程序的名称,该处理程序接收成功的服务器端事件的结果。

context

启动回调之前在客户端计算的客户端脚本。脚本的结果传回客户端事件处理程序。

clientErrorCallback

客户端事件处理程序的名称,该处理程序在服务器端事件处理程序出现错误时接收结果。

useAsync

true 表示同步执行回调;false 表示异步执行回调。

 

 

返回值

调用客户端回调的客户端函数的名称。
另外页面对应的cs类还要实现 ICallbackEventHandler 接口 
string ICallbackEventHandler.GetCallbackResult()
    {
返回处理结果给客户端 argument
                //throw new Exception("The method or operation is not implemented.");
    }
    void ICallbackEventHandler.RaiseCallbackEvent(string eventArgument)
    {
处理程序
               //throw new Exception("The method or operation is not implemented.");
    }
客户端:
定义一个脚本函数 CallToServer() 在此函数体内要调用 GetCallbackEventReference(...)函数 定义一个脚本快,处理回调换回后的事情 
handleResultFromServer(args ,contex)
 执行顺序为:当客户端事件调用GetCallbackEventReference(...)事件时,服务器首先执行
void ICallbackEventHandler.RaiseCallbackEvent(string eventArgument)
然后string ICallbackEventHandler.GetCallbackResult() 此函数返回的结果交给客户端
handleResultFromServer(...)
 
原创粉丝点击