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>

 

结果:

image

posted @ 2009-05-04 22:27  Localhost  阅读(537)  评论(0编辑  收藏  举报