主要是用到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>