用ICallbackEventHandler接口 实现无刷新回传
成功代码:
<%@ Page Language= "C# " AutoEventWireup= "true " CodeFile= "testClientCallBack.aspx.cs " Inherits= "testClientCallBack " %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN " "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<script type= "text/javascript ">
function CallServer()
{
var product = "test ";
<%= ClientScript.GetCallbackEventReference(this, "product ", "ReceiveServerData ",null)%> ;
}
function ReceiveServerData(rValue)
{
//alert(rValue[0]+ '/ '+rValue[1]+ '/ '+rValue[2]+ '/ ');
alert(rValue);
}
</script>
<html xmlns= "http://www.w3.org/1999/xhtml " >
<head runat= "server ">
<title> 无标题页 </title>
</head>
<body>
<form id= "form1 " runat= "server ">
<div>
<button onclick= "CallServer() "> CallServer </button>
</div>
</form>
</body>
</html>
----------------------
private string CallBackValue = string.Empty;
string ICallbackEventHandler.GetCallbackResult()
{
string a1 = "test ";
return CallBackValue + ",ok ";
// return a1;
}
void ICallbackEventHandler.RaiseCallbackEvent(string eventArgument)
{
this.CallBackValue = eventArgument;
}
现在想返回一个数组
string[] ICallbackEventHandler.GetCallbackResult()
{
string[] a1 = new string[]{ "a ", "b ", "c "};
//return CallBackValue + ",ok ";
return a1;
}
报错
讲
“ICallbackEventHandler.GetCallbackResult”不是接口成员
[解决办法]
up
[解决办法]
UP,可惜我也不清楚,帮你UP一下
[解决办法]
关注..
[解决办法]
返回以控件为目标的回调事件的结果。
命名空间:System.Web.UI
程序集:System.Web(在 system.web.dll 中)
语法
Visual Basic(声明)
Function GetCallbackResult As String
Visual Basic(用法)
Dim instance As ICallbackEventHandler
Dim returnValue As String
returnValue = instance.GetCallbackResult
C#
string GetCallbackResult ()
[解决办法]
接口定义只能返回string
你可以传递JSON对象,前台用eval
string ICallbackEventHandler.GetCallbackResult()
{
string[] a1 = new string[]{ "a ", "b ", "c "};
return "[ 'a ', 'b ', 'c '] ";
}
var array = eval(responseText);
[解决办法]
搞清楚形势。接口已经给你准好了,现在是你还没有用好,就问能不能破坏它的问题。
好比如说你问我,“我是个怕强高手,那么能不能我到人家拜访时只跳窗户进去不走正门”?
软件开发还算不错的技术,我建议你先学好功课,再破坏。
[解决办法]
你让Vs自动生成接口实现函数,不要自己写容易出错,点右键!