导航: 好喜爱学习网 >> 网站制作 >> 网页制作技巧 >> 利用ICallbackEventHandle实现类似AJAX的无刷新页面
相关文章
最新文章
文章内容
利用ICallbackEventHandle实现类似AJAX的无刷新页面
作者:未知 来源:网络收集 录入:管理员
 先看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

[1] [2] 

E-MAIL:309076721@163.com
本站为非营利性质个人网站,建站只为个人爱好与学习,内容大多为电脑技术教程;
网站内容来源于互联网收集整理,禁止用于非法途径,如发现本网站上有侵权的文章请联系我们,我们会尽快删除;
本站不对站点内容准确性、完整性和真实性作任何承诺,由此产生的后果本站不承担任何责任,对以上引起的一切法律纠纷本站无权利承担。