| WebForm_DoCallback('__Page',arg,ReceiveServerData,context,null,false) |
| <%@ page language="C#" CodeFile="ServerTime.aspx.cs" Inherits="ServerTime_aspx" %> <html> <head> <title>Server Time</title> <script language="javascript"> function GetServerTime() { var message = ''; var context = ''; <%=sCallBackFunctionInvocation%> } function ShowServerTime(timeMessage, context) { alert('现在服务器上的时间是:n' + timeMessage); } </script> </head> <body> <form id="MainForm" runat="server"> <input type="button" value="得到服务器端时间" onclick="GetServerTime();" /> </form> </body> </html> |
| using System; using System.Web.UI; public partial class ServerTime_aspx : Page,ICallbackEventHandler { //一定要实现ICallbackEventHandler借口 public string sCallBackFunctionInvocation; void Page_Load(object sender, System.EventArgs e) { sCallBackFunctionInvocation = Page.ClientScript.GetCallbackEventReference(this, "message", "ShowServerTime", "context"); } public string RaiseCallbackEvent(string eventArgument) { return DateTime.Now.ToString(); } } |

用户评论