頁面代碼:
<script type="text/javascript">
function ReceiveServerData(rValue)
{
alert(rValue);
}
</script>
<input id="Button1" type="button" value="button" onclick ="CallServer('Client')" />
服務端代碼:
public partial class back2 : System.Web.UI.Page,System .Web .UI .ICallbackEventHandler
{
public string CallBackValue = null;
PRotected void Page_Load(object sender, EventArgs e)
{
}
// 注冊腳本到前臺頁面
protected void Page_PreRender(object sender, EventArgs e)
{
RegClientScript();
}
// Javascript函數(服務器端事件的客戶端回調)
protected void RegClientScript()
{
ClientScriptManager cs = Page.ClientScript;
string jstxt=@"
function CallServer(msgid)
{
" + cs.GetCallbackEventReference(this, "msgid", "ReceiveServerData", null) + @";
}";
cs.RegisterStartupScript(this.GetType(), "callserver", jstxt, true);
}
//ICallbackEventHandler接口
//把值傳到前臺
string ICallbackEventHandler.GetCallbackResult()
{
return CallBackValue + ",Server";
}
//按受前臺的參數
void ICallbackEventHandler.RaiseCallbackEvent(string eventArgument)
{
this.CallBackValue = eventArgument;
}
}
http://m.survivalescaperooms.com/chy710/archive/2006/12/26/604118.html
新聞熱點
疑難解答