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

AJAX技术
[ASP.NET AJAX]Function对象及Type类的方法介绍
163 AJAX Tab
AJAX根据城市名,自动完成相应的城市信息
AJAX天气预报前台
配合AJAX天气预报的webService 之asp
用Ajax来控制书签和回退按钮的代码
prototype试用整理资料
如何成为AJAX高手
纯AJAX分页,V0.2版 下载+演示
ajax 自动完成下拉框 自动提示位置问题
完美ajax类 支持事件
AJAXCALL
天枫AJAX天气预报系统V1.0
Ajax技术(WEB无刷新提交数据)
AjaxUI:滑动条
用实现ajax读博客rss示例代码
ajax中指定innerHTML时如何应用其中的SCRIPT的研究
AJAX实现web页面中级联菜单的设计
AJAX和DOM的运行经验
用ajax自动加载blogjava和博客园的rss

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


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