Client端的寫法:
<script type="text/javascript">
function functionName() { PageMethods.serverFunctionName(param1,param2, onSuccess, onFail); } function onSuccess(response, context, method) { if (method == ' sendCommandToModifyChance') { alert(response); } } function onFail(response, context, method) { if (method == ' sendCommandToModifyChance') { alert("command sned error!"); } } </script>
Server 端的寫法:
[System.Web.Services.WebMethod]//一定要宣告成public static public static void serverFunctionName(param1,param2){
//do something }
注意事項:
1. Server端的方法上面要宣告[System.Web.Services.WebMethod ]的標籤
2. 要被Client呼叫的方法一定要宣告成public static
3. 在<form>標籤下加入ScriptManager
form id="form1" runat="server"> <asp:ScriptManager ID=" ScriptManager1" runat="server" EnablePageMethods="true"> </asp:ScriptManager>
沒有留言:
張貼留言