当前位置: 首页 > 图文教程 > 网络编程 > ASP.NET > 用ICallbackEventHandler实现客户端与服务器端异步

ASP.NET
dotNET下面调用Access中存储过程的方法
DataSet 的 Merge 方法研究
C#中using关键字的使用
Visual C#程序设计技巧小结
Creating GUIDs in c#
C#覆盖虚接口
在C#中应用哈希表(Hashtable)
对C#泛型中的new()约束的一点思考
身份证15To18 的算法(C#)
ADO.NET的结构体系。
ADO.NET的DataSet和ADO的Recordset的比较
OpenGLStepbyS
.NET对软件安装的冲击
IsVS.NETreadyforenterprise?(1)
IsVS.NETreadyforenterprise?(5)
IsVS.NETreadyforenterprise?(6)
.Net和Java有何相似之处
Hi,现在我们暂时不谈Passport
替代System.Web.Mail的新类库(新增邮件列表功能)
C#和VB.NET的区别

ASP.NET 中的 用ICallbackEventHandler实现客户端与服务器端异步


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-11-03   浏览: 75 ::
收藏到网摘: n/a

     页面代码:
  <script type="text/javascript">
   function ReceiveServerData(rValue)
   {
   alert(rValue);
   }
   </script>
  <input id="Button1" type="button" value="button" onclick ="CallServer('Client')" />
  服务端代码:
  public partial class back2 : System.Web.UI.Page,System .Web .UI .ICallbackEventHandler
  {
   public string CallBackValue = null;
   protected void Page_Load(object sender, EventArgs e)
   {
  
   }
   // 注册脚本到前台页面
   protected void Page_PreRender(object sender, EventArgs e)
   {
   RegClientScript();
   }
   // javascript函数(服务器端事件的客户端回调)
   protected void RegClientScript()
   {
   ClientScriptManager cs = Page.ClientScript;
   string jstxt=@"
   function CallServer(msgid)
   {
   " + cs.GetCallbackEventReference(this, "msgid", "ReceiveServerData", null) + @";
   }";
   cs.RegisterStartupScript(this.GetType(), "callserver", jstxt, true);
   }
   //ICallbackEventHandler接口
   //把值传到前台
   string ICallbackEventHandler.GetCallbackResult()
   {
   return CallBackValue + ",Server";
   }
  
   //按受前台的参数
   void ICallbackEventHandler.RaiseCallbackEvent(string eventArgument)
   {
   this.CallBackValue = eventArgument;
   }
  }
  http://www.cnblogs.com/chy710/archive/2006/12/26/604118.html