客户端回调机制

lgz7667597 2008-09-04 01:29:30
客户端回调机制是什么?如何理解?回调的生命周期是怎样的?和脚本是如何建立起联系的?
如何实现ICallbackEventHandler接口?

这些都搞的不是很清楚,各位大哥们请赐教~!!
...全文
73 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
cs360846395 2012-03-29
  • 打赏
  • 举报
回复
没看懂
lgz7667597 2008-09-04
  • 打赏
  • 举报
回复
谢谢一楼!!
callbackScript = "function CallServer(arg, context)" +
"{ " + cbReference + "} ;";
CallServer(arg,context)中第二个参数有什么用途?谢谢
viki117 2008-09-04
  • 打赏
  • 举报
回复
不明白啊,学习
JeffChung 2008-09-04
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 freeflying1222 的回复:]
都搞不清楚还是得找本书来慢慢看的!
[/Quote]

同意,在这里讲终究没有书上讲的细致有条理
xl888 2008-09-04
  • 打赏
  • 举报
回复
Invoke
格拉 2008-09-04
  • 打赏
  • 举报
回复
帮顶
LQknife 2008-09-04
  • 打赏
  • 举报
回复
脚本啊 晓习
freeflying1222 2008-09-04
  • 打赏
  • 举报
回复
都搞不清楚还是得找本书来慢慢看的!
Fioit 2008-09-04
  • 打赏
  • 举报
回复
1. 页面ICallbackEventHandler接口,实现RaiseCallbackEvent和GetCallbackResult()两个方法,以接受客户端的请求和进行返回。

2. Page.ClientScript.RegisterClientScriptBlock注册你要调用服务端的JS函数。
Page.ClientScript.GetCallbackEventReference注册处理服务器返回值的函数


csShooter 2008-09-04
  • 打赏
  • 举报
回复
<%@ 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/xhtml" >
<head runat="server">
<script type="text/javascript">
function LookUpStock()
{
var lb = document.forms[0].ListBox1;
var product = lb.options[lb.selectedIndex].text
CallServer(product, "");
}

function ReceiveServerData(rValue)
{
Results.innerText = rValue;
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ListBox ID="ListBox1" Runat="server"></asp:ListBox>
<br />
<br />
<button onclick="LookUpStock()">Look Up Stock</button>
<br />
<br />
Items in stock: <span ID="Results"></span>
<br />
</div>
</form>
</body>
</html>

// ClientCallback.aspx.cs code-behind page
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.ICallbackEventHandler
{
protected System.Collections.Specialized.ListDictionary catalog;
protected void Page_Load(object sender, EventArgs e)
{
String cbReference =
Page.ClientScript.GetCallbackEventReference(this,
"arg", "ReceiveServerData", "context");
String callbackScript;
callbackScript = "function CallServer(arg, context)" +
"{ " + cbReference + "} ;";
Page.ClientScript.RegisterClientScriptBlock(this.GetType(),
"CallServer", callbackScript, true);

catalog = new System.Collections.Specialized.ListDictionary();
catalog.Add("monitor", 12);
catalog.Add("laptop", 10);
catalog.Add("keyboard", 23);
catalog.Add("mouse", 17);

ListBox1.DataSource = catalog;
ListBox1.DataTextField = "key";
ListBox1.DataBind();
}

public String RaiseCallbackEvent(String eventArgument)
{
String returnValue;
if (catalog[eventArgument] == null)
{
returnValue = "-1";
}
else
{
returnValue = catalog[eventArgument].ToString();
}
return returnValue;
}
}

110,534

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧