.net2.0客户端回调实现 (C#) 示例
2006-06-05 18:39
302 查看
照搬MSDN2005的代码实现无刷回调,老是提示:
错误1“ClientCallback”不会实现接口成员“System.Web.UI.ICallbackEventHandler.RaiseCallbackEvent(string)”。“ClientCallback.RaiseCallbackEvent(string)”或者是静态、非公共的,或者有错误的返回类型。
错误2“ClientCallback”不会实现接口成员“System.Web.UI.ICallbackEventHandler.GetCallbackResult()”
<%@ 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;
}
}
更改后的
//////////////////////////////
public String RaiseCallbackEvent(String eventArgument)
{
String returnValue;
if (catalog[eventArgument] == null)
{
returnValue = "-1";
}
else
{
returnValue = catalog[eventArgument].ToString();
}
return returnValue;
}
//////////////////////////////
改成如下:
string earg = "";
#region ICallbackEventHandler 成员
public string GetCallbackResult()
{
String returnValue;
if (catalog[earg] == null)
{
returnValue = "-1";
}
else
{
returnValue = catalog[earg].ToString();
}
return returnValue;
}
public void RaiseCallbackEvent(string eventArgument)
{
//throw new Exception("The method or operation is not implemented.");
earg = eventArgument;
}
#endregion
可以体验到了回调的感觉了。。。。。。。。。。。。
错误1“ClientCallback”不会实现接口成员“System.Web.UI.ICallbackEventHandler.RaiseCallbackEvent(string)”。“ClientCallback.RaiseCallbackEvent(string)”或者是静态、非公共的,或者有错误的返回类型。
错误2“ClientCallback”不会实现接口成员“System.Web.UI.ICallbackEventHandler.GetCallbackResult()”
<%@ 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;
}
}
更改后的
//////////////////////////////
public String RaiseCallbackEvent(String eventArgument)
{
String returnValue;
if (catalog[eventArgument] == null)
{
returnValue = "-1";
}
else
{
returnValue = catalog[eventArgument].ToString();
}
return returnValue;
}
//////////////////////////////
改成如下:
string earg = "";
#region ICallbackEventHandler 成员
public string GetCallbackResult()
{
String returnValue;
if (catalog[earg] == null)
{
returnValue = "-1";
}
else
{
returnValue = catalog[earg].ToString();
}
return returnValue;
}
public void RaiseCallbackEvent(string eventArgument)
{
//throw new Exception("The method or operation is not implemented.");
earg = eventArgument;
}
#endregion
可以体验到了回调的感觉了。。。。。。。。。。。。
相关文章推荐
- ASP.NET 客户端回调实现 (C#) 示例 (VS2005)MSDN 错误处理
- 客户端回调实现 (C#) 示例
- 客户端回调实现 (C#) 示例
- 客户端回调实现 (C#) 示例
- 客户端回调实现 (C#) 示例
- ASP.NET 客户端回调实现 (C#) 示例
- 客户端回调实现 (C#) 示例
- 客户端回调实现 (C#) 示例
- 如何在无刷新页面的情况下实现客户端回调实例(C#)—MSDN学习笔记
- ASP.NET2.0实现无刷新客户端回调的Callback机制(示例源码)
- c#实例化继承类,必须对被继承类的程序集做引用 .net core Redis分布式缓存客户端实现逻辑分析及示例demo 数据库笔记之索引和事务 centos 7下安装python 3.6笔记 你大波哥~ C#开源框架(转载) JSON C# Class Generator ---由json字符串生成C#实体类的工具
- 如何在无刷新页面的情况下实现客户端回调实例(C#)—MSDN学习笔记
- 【出版直播】博客园征途系列,《设计模式——基于C#的工程化实现与扩展》电子书、示例代码发布,互动网预订开始
- C#下如何实现服务器+客户端的聊天程序
- C#实现大文件分块发送到客户端
- 12_C# 实现VMS客户端——控件_ComboItem
- ASP.NET2.0实现无刷新客户端回调
- C#SocketAsyncEventArgs实现高效能多并发TCPSocket通信 (客户端实现)
- C#实现数据库事务处理示例代码
- 17_C# 实现VMS客户端——控件_TableLayoutPanel