主要是用到ScriptManger,老知识Mark一下,ScriptManager要EnablePageMethods="true"

后台

using System.Web.Script.Services;
using System.Web.Services;
[WebMethod] [ScriptMethod] public static string GetValue(string userID) { return userID+DateTime.Now.ToString(); }

 

前台

<head runat="server">
    <title>无标题页</title>
 

    <script language="javascript" type="text/javascript">
        function CheckUserID() {
            PageMethods.GetValue('Anson', function(result) {
                alert(result);
            });
        }
    </script>

</head>
<body>
    <form id="form1" runat="server"> 
     <asp:ScriptManager runat="server" EnablePageMethods="true">
    </asp:ScriptManager>
    <div>
        <input type="button" value="Test" onclick="CheckUserID();return false;" />
    </div>
    </form>
</body>

  

 

posted on 2013-07-25 14:32  gzh4455  阅读(260)  评论(0编辑  收藏  举报