All articles| All Pictures| All Softwares| All Video| Go home page| Write articles| Upload pictures

Reading number is top 10 articles
C#中HelpProvider组件应用实例
PHP实例:动态网页PHP+MYSQL如何插入记录到数据库_[PHP教程]
Sql,Server2005实现远程备份数据库_mssql学习_编程技术
ACCESS改为SQL需要注意哪几个地方_[SQL,Server教程]
如何利用.NET,Framework使用RSS,feed_[Asp.Net教程]
SQL,Server如何得详细错误处理信息_[SQL,Server教程]
在c#中如何操作文本文件_[Asp.Net教程]
不妨来做个尝试:UpdatePanel,for,ASP.NET,MVC_[Asp.Net教程]
详细学习PHP中对文件和目录的操作方法_php资料_编程技术
String.Empty、NULL、“”的不同之处_[Asp.Net教程]
Reading number is top 10 pictures
More attractive than sora aoi1
The girl of like self-time
女人化妆前后的对比
A man's favorite things12
Forced sex girl living abroad1
The real super beauty11
Soong ching ling's former residence1
8090后结婚的各种XX事
Exquisite decoration is not paying too much2
清纯性感的美眉2
Download software ranking
美女写真1
变速齿轮3.26
Detective task-the top secret prostitution files
Sora aoi, the nurse, uniform ,nursing assistant
SP4 for SQL2000
电车之狼R
Tram sex maniac 2 (H) rar bag14
Unix video tutorial11
1400篇各类破解文章
Sora aoi‘s film--Lust fan wall
delv published in(发表于) 2014/1/6 9:10:06 Edit(编辑)
利用ICallbackEventHandle实现类似AJAX的无刷新页面_[Asp.Net教程]

利用ICallbackEventHandle实现类似AJAX的无刷新页面_[Asp.Net教程]

利用ICallbackEventHandle实现类似AJAX的无刷新页面_[Asp.Net教程]

先看MSDN Library 2005上的这个例子!

------ ClientCallback.aspx ------
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="ClientCallback.aspx.cs" ­ Inherits="ClientCallback" %>





Callback Test





onclick="CallServer('argument', 'context')"/>




-------- 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接收服务器返回的数据,




使用CallServer('argument', 'context')传递数据到服务器。


客户端ok了,接下来是服务器端,实现ICallbackEventHandle­ 接口,


private string returnStr;
public void RaiseCallbackEvent(String eventArgument)
{
returnStr = eventArgument.ToUpper();
return;
}

public string GetCallbackResult()
{
return returnStr;
}


最后,将客户端方法和服务器端的方法关联起来,在Page_Load中实现,


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);


大功告成!


这种方法也能达到类似ajax的无刷新页面,而且实现起来十分简单。


来源:博客园





添加到del.icio.us 添加到新浪ViVi 添加到百度搜藏 添加到POCO网摘 添加到天天网摘365Key 添加到和讯网摘 添加到天极网摘 添加到黑米书签 添加到QQ书签 添加到雅虎收藏 添加到奇客发现 diigo it 添加到饭否 添加到飞豆订阅 添加到抓虾收藏 添加到鲜果订阅 digg it 貼到funP 添加到有道阅读 Live Favorites 添加到Newsvine 打印本页 用Email发送本页 在Facebook上分享


Disclaimer Privacy Policy About us Site Map

If you have any requirements, please contact webmaster。(如果有什么要求,请联系站长)
Copyright ©2011-
uuhomepage.com, Inc. All rights reserved.