页面如下:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true">
</asp:ScriptManager>
<input id="Button1" type="button" value="button" onclick="return Button1_onclick()" />
<script language="javascript" type="text/javascript">
function Button1_onclick() {
PageMethods.GetServerTime(alt);
}
function alt(result) {
alert(result);
}
</script>
</form>
</body>
</html>
后台代码如下:
using System;
using System.Web;
using System.Web.UI;
public partial class Default2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
[System.Web.Services.WebMethod]
public static string GetServerTime()
{
return DateTime.Today.ToString();
}
}