ICallbackEventHandler实现无刷新回调
前台页面:
<body>
<form id="form1" runat="server">
<div>
<input id="txtMessage" style="width: 353px" type="text" />
<input id="Button1" type="button" value="Call to Server" onclick="CallServer();" />
<br />
result:<input id="txtResult" style="width: 442px" type="text" /></div>
</form>
</body>
<script type="text/javascript">
function CallServer()
{
var product = document.getElementById("txtMessage").value;//前台数据传到后台处理
//返回后台处理后的数据到前台,用前台函数ReceiveServerData来接收
<%= ClientScript.GetCallbackEventReference(this, "product", "ReceiveServerData",null)%>;
}
function ReceiveServerData(rValue)
{
//alert(rValue);
document.getElementById("txtResult").value = rValue;
}
</script>
public partial class testNoRefresh : System.Web.UI.Page, System.Web.UI.ICallbackEventHandler
{
protected void Page_Load(object sender, EventArgs e)
{

}

//定义一个字符串,回调的结果信息将保存在该字符串中
private string CallBackValue = string.Empty;


//引发回调事件处理
void ICallbackEventHandler.RaiseCallbackEvent(string eventArgument)
{
this.CallBackValue = "客户端在[" + DateTime.Now.ToString() + "]传送来 [" + eventArgument + "]!";
}

//回传回调结果
string ICallbackEventHandler.GetCallbackResult()
{
return CallBackValue;
}
}









前台脚本:















后台代码:























