页面代码:
<script type="texto/javascript">
função ReceiveServerData(rValue)
{
alerta(rValor);
}
</script>
<input id="Button1" type="button" value="button" onclick ="CallServer('Client')" />
服务端代码:
classe parcial pública back2: System.Web.UI.Page,System .Web .UI .ICallbackEventHandler
{
string pública CallBackValue = null;
protegido void Page_Load (remetente do objeto, EventArgs e)
{
}
// 注册脚本到前台页面
protegido void Page_PreRender (remetente do objeto, EventArgs e)
{
RegClientScript();
}
// código javascript(服务器端事件的客户端回调)
RegClientScript vazio protegido()
{
ClientScriptManager cs = Page.ClientScript;
string jstxt=@"
função CallServer(msgstr)
{
" + cs.GetCallbackEventReference(this, "msgid", "ReceiveServerData", null) + @";
}";
cs.RegisterStartupScript(this.GetType(), "callserver", jstxt, true);
}
//ICallbackEventHandler接口
//把值传到前台
string ICallbackEventHandler.GetCallbackResult()
{
return CallBackValue + ",Servidor";
}
//按受前台的参数
void ICallbackEventHandler.RaiseCallbackEvent(string eventArgument)
{
this.CallBackValue = eventArgument;
}
}
http://www.cnblogs.com/chy710/archive/2006/12/26/604118.html