比如
'建立Page Method
_
_
Public Shared Function GetServerTime(ByVal format As String) As String
'调用服务器端时间
Return Now.ToString(format)
End Function
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
'建立调用后端Web Services的javascript
Dim js As String
js = ""
js += "function CallWebServices(){"
js += " PageMethods.GetServerTime('yyyy/MM/dd HH:mm:ss',onOK);"
js += "}"
js += "function onOK(returnData){"
js += " $get('TextBox1').value=returnData;"
js += "}"
js = ""
Me.ClientScript.RegisterStartupScript(GetType(String), "", js)
'将调用后端Web Services的javascript附加到Button1的onclick事件上
Me.Button1.Attributes("onclick") = "CallWebServices();"
'设置 EnablePageMethods
Me.ScriptManager1.EnablePageMethods = True
End Sub
End Class
前台页面
本文作者:佚名 来源:http://www.cnblogs.com/jackyrong/
CIO之家 www.ciozj.com 微信公众号:imciow