客户端异步
- 需要实现的接口:
实现ICallbackEventHandler接口
实现RaiseCallbackEvent和GetCallbackResult接口方法
- 需要实现的客户端三个脚本函数
实现一个调用帮助器方法的函数
实现一个clientCallBack的函数
实现一个执行对服务器的实际请求的Helper函数
Demo:
namespace DataSetXmlDemo
{
public partial class fmCallBack : System.Web.UI.Page,ICallbackEventHandler
{
string resutl;
protected void Page_Load(object sender, EventArgs e)
{
}
#region ICallbackEventHandler Members
public string GetCallbackResult()
{
return resutl;
}
public void RaiseCallbackEvent(string eventArgument)
{
resutl = "Server Return Data:"+ eventArgument;
}
#endregion
}
}
<head runat="server">
<title>Untitled Page</title>
<script type="text/javascript">
function ReceiveServerData(result1,contex)
{
contex.innerHTML=result1;
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox><br />
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label><br />
<input id="Button1" type="button" value="button" onclick="<%=ClientScript.GetCallbackEventReference(this,"document.form1.TextBox1.value","ReceiveServerData","Label1")%>" /> </div>
</form>
</body>
</html>