PageMethods is not Defined in ASPX Page

心不动则不痛 提交于 2019-11-29 05:38:59

EnablePageMethods actually only interacts with methods of a Page subclass that are public, static, and attributed as a WebMethod.

GetCompanyList has 2 of those and just also needs to be static.

[System.Web.Services.WebMethod()]
[System.Web.Script.Services.ScriptMethod()]
public static IEnumerable<CompanyMinimum> GetCompanyList(int officeId) {
    // ...
}

And, I suspect what's happening is that it's leaving PageMethods undefined client-side if it doesn't find any methods that have all 3.

You can invoke ASP.NET AJAX Page Methods via jQuery, like this:

$.ajax({
    type: "POST",
    url: "PageName.aspx/MethodName",
    data: "{}",
    contentType: "application/json; charset=utf-8",
    dataType: "json",
    success: function(msg) {
        // Do something interesting here.
    }
});

maybe you are using Routing in your pages. then must be set real path after call PageMethods:

PageMethods.set_path("<%=ResolveUrl("~/YourPage.aspx")%>");
PageMethods.YourMethod(param, OnSuccess, OnError);

One answer from another solution that I think should be represented is if this error occurs on your server but not locally is to place the empty MyPage.aspx placeholder file and now it works on the production server too.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!