`
javasee
  • 浏览: 961380 次
  • 性别: Icon_minigender_1
  • 来自: 北京
文章分类
社区版块
存档分类
最新评论

董大伟 ASP.NET与AJAX 书vb.net转c#源代码一CallBack 获取Server端时间

 
阅读更多
转换C#后代码 using System; using System.Data; using System.Configuration; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; public partial class _Default : System.Web.UI.Page,System.Web.UI.ICallbackEventHandler { private string returnValue; protected void Page_Load(object sender, EventArgs e) { string cbReference; cbReference = Page.ClientScript.GetCallbackEventReference(this, "''", "ReceiveServerData", ""); Button1.Attributes["onclick"] = cbReference; string ReceiverScript = ""; ReceiverScript += "<script>/n"; ReceiverScript += " function ReceiveServerData(DataFromServer)/n"; ReceiverScript += "{/n"; ReceiverScript += "document.all." + TextBox1.ClientID + ".value=DataFromServer;/n"; ReceiverScript += "}/n"; ReceiverScript += "</script>/n"; Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "ReceiverScript",ReceiverScript); } public string GetCallbackResult() { return DateTime.Now.ToLongTimeString(); } public void RaiseCallbackEvent(string eventArgument) { returnValue=eventArgument; } protected void Button1_Click(object sender, EventArgs e) { } //////////////////////////////////////////////////////// 原VB代码 Partial Class _Default Inherits System.Web.UI.Page Implements System.Web.UI.ICallbackEventHandler Protected Overridable Function GetCallbackResult() As String Implements System.Web.UI.ICallbackEventHandler.GetCallbackResult Return Now End Function Dim returnValue As String Public Sub RaiseCallbackEvent(ByVal eventArgument As String) Implements System.Web.UI.ICallbackEventHandler.RaiseCallbackEvent returnValue = eventArgument End Sub Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load Dim cbReference As String cbReference = Page.ClientScript.GetCallbackEventReference(Me, "''", "ReceiveServerData", "") Button1.Attributes("onclick") = cbReference Dim ReceiverScript As String = "" ReceiverScript += vbCrLf + "<script>" ReceiverScript += vbCrLf + "function ReceiveServerData(DataFromServer)" ReceiverScript += vbCrLf + "{" ReceiverScript += vbCrLf + "document.all." + TextBox1.ClientID + ".value=DataFromServer;" ReceiverScript += vbCrLf + "}" ReceiverScript += vbCrLf + "</script>" Page.ClientScript.RegisterClientScriptBlock(GetType(String), "ReceiverScript", ReceiverScript) End Sub End Class
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics