渔鱼

人生豪迈,在此一博!

  博客园 :: 首页 :: 博问 :: 闪存 :: :: 联系 :: 订阅 订阅 :: 管理 ::

页面如下:

<%@ 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();
    }
}

posted on 2009-06-20 22:38  博闻李  阅读(781)  评论(0编辑  收藏  举报