Ajax--调用PageMethod
PageMethods:
using System.Web.Services; [WebMethod] public static string Ok() { return "this is function ok!"; }
注意:using及WebMethod
ScriptManager:
<asp:ScriptManager ID="sm" runat="server" EnablePageMethods="true" > </asp:ScriptManager>
注意:EnablePageMethods="true",否则无法启用PageMethod
Js:
<script type="text/javascript"> function btn_click(){ PageMethods.Ok(onSuccessed); } function onSuccessed(result){ $get("result").innerHTML=result; } </script>
结果: