aspx页面代码
<asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true" />
<input type="button" value="Get Current Time" οnclick="getCurrentTime()" />
<script language="javascript" type="text/javascript">
function getCurrentTime()
{
PageMethods.GetCurrentTime(getCurrentTimeSucceeded);
}
function getCurrentTimeSucceeded(result)
{
alert(result);
}
</script>
对应的aspx.cs页面方法代码
[WebMethod]//需要添加的标记引用自using System.Web.Services;命名空间
public static DateTime GetCurrentTime()
{
return DateTime.UtcNow;
}