页面如下:
<%@ 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 >
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();
}
}