PageMethods is not Defined in ASPX Page

前端 未结 4 914
猫巷女王i
猫巷女王i 2020-12-17 10:32

I\'m looking at some old code that I can only assume worked at one time.

MyPage.aspx:

function GetCompanyList(officeId) {
    var co         


        
相关标签:
4条回答
  • 2020-12-17 10:56

    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.
        }
    });
    
    0 讨论(0)
  • 2020-12-17 11:02

    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.

    0 讨论(0)
  • 2020-12-17 11:09

    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);
    
    0 讨论(0)
  • 2020-12-17 11:16

    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.

    0 讨论(0)
提交回复
热议问题