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

AJAX技术
AJAX快速入门之HTTP协议基础
使用AJAX的十大理由
用Oracle JDeveloper 10.1.3构建Ajax应用程序
用AJAX+J2EE实现一个网上会议室系统
AJAX在VS2005中的简单应用
用AJAX编写一个简单的相册
利用AJAX技术提高搜索引擎排名
在ASP.NET中使用AJAX的简单方法
AJAX和Web开发新技术:Dynamic Faces
开发保留标准浏览器功能的AJAX应用程序
AJAX编程实践之与服务器通信
AJAX并不神秘:揭密各种AJAX控件和类库
使用AJAX技术构建更优秀的Web应用程序
使用GWT开发AJAX应用程序
为AJAX应用程序构建一个错误提交系统
总结AJAX相关JS代码片段和浏览器模型
全面剖析XMLHttpRequest对象
独立的思想 由AJAX应用引发的深思
一款经典的ajax登录页面 后台asp.net
ajax 调用后台方法大家可以讨论下

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


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-11-03   浏览: 59 ::
收藏到网摘: 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接收服务器返回的数据,
&