页面代码:
<skrip tipe="teks/javascript">
fungsi TerimaServerData(rValue)
{
peringatan(Nilai r);
}
</skrip>
<input id="Button1" type="button" value="button" onclick ="CallServer('Klien')" />
服务端代码:
kelas parsial publik back2 : System.Web.UI.Page,System .Web .UI .ICallbackEventHandler
{
string publik CallBackValue = null;
dilindungi kekosongan Page_Load (pengirim objek, EventArgs e)
{
}
// 注册脚本到前台页面
dilindungi kekosongan Page_PreRender(pengirim objek, EventArgs e)
{
RegClientScript();
}
// javascript函数(服务器端事件的客户端回调)
dilindungi kekosongan RegClientScript()
{
ClientScriptManager cs = Halaman.ClientScript;
string jstxt=@"
fungsi CallServer(msgstr)
{
" + cs.GetCallbackEventReference(ini, "msgstr", "ReceiveServerData", null) + @";
}";
cs.RegisterStartupScript(this.GetType(), "callserver", jstxt, true);
}
//ICallbackEventHandler接口
//把值传到前台
string ICallbackEventHandler.GetCallbackResult()
{
kembalikan CallBackValue + ",Server";
}
//按受前台的参数
membatalkan ICallbackEventHandler.RaiseCallbackEvent(string eventArgument)
{
this.CallBackValue = eventArgument;
}
}
http://www.cnblogs.com/chy710/archive/2006/12/26/604118.html