当前位置: 首页 > 图文教程 > 网络编程 > AJAX技术 > 利用ICallbackEventHandle实现类似AJAX的无刷新页面

AJAX技术
什么是ajax的定义
ajaxrequest.js ajaxrequest 0.7最新版 使用AJAXRequest进行AJAX应用程序开发入门小技巧
javascript ajax类AJAXRequest2007-12-31 更新
ajax类AJAXRequest v0.8.01 2008-01-31 最新版附使用帮助
php ajax无刷新分页,支持id定位
js统计网页在线时间的脚本
用Ajax读取xml文件的简单例子
Ajax 的六个误区小结分析
Ajax核心XMLHTTP组件资料
ie7下利用ajax跨域盗取cookie的解决办法
ajax AjaxDownloader.js[modified]
Ajax获取页面被缓存的解决方法
php ajax无刷新上传图片实例代码
ajax实时任务提示功能的实现代码
php ajax网站浏览统计功能的简单实现
rails制作rss feed代码
一句话解决AJAX中文乱码问题[推荐]
有史以来最简单的AJAX回调库
使用ajax技术无刷新动态调用股票信息
ajax实例入门代码

AJAX技术 中的 利用ICallbackEventHandle实现类似AJAX的无刷新页面


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

 先看MSDN Library 2005上的这个例子!
------ ClientCallback.aspx ------
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="ClientCallback.aspx.cs" ­ Inherits="ClientCallback" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/­ xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtm­ l" >
    <head id="Head1" runat="server">
        <title>Callback Test</title>
        <script type="text/javascript">
        function ReceiveServerData(receivedStr, context)
        {
            alert(receivedStr);
        }
        </script>
    </head>
        <body>
          <form id="form1" runat="server">
            <input type="button" value="Callback" onclick="CallServer(’argument’, ’context’)"/><br />
          </form>
    </body>
</html>-------- ClientCallbacp.aspx.cs  -----------
// ClientCallback.aspx.cs 
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;­ 
using System.Web.UI.HtmlControls;
public partial class ClientCallback : System.Web.UI.Page, System.Web.UI.ICallbackEventHandle­ r
{
    void Page_Load(object sender, EventArgs e)
    {
        ClientScriptManager cm = Page.ClientScript;
        String cbReference = cm.GetCallbackEventReference(this,­ "arg", "ReceiveServerData", "");
        String callbackScript = "function CallServer(arg, context) {" + cbReference + "; }";
        cm.RegisterClientScriptBlock(this.­ GetType(), "CallServer", callbackScript, true);
    }
    private string returnStr;
    //function called by client, executed on server

    public void RaiseCallbackEvent(String eventArgument)    
    {
        //do something with return argument
        returnStr = eventArgument.ToUpper();
        return;
    }
    
    //function that sends result?
    public string GetCallbackResult()
    {
        return returnStr;
    }
}
客户端用ReceiveServerData接收服务器返回的数据,
&