PageMethods is not Defined in ASPX Page

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


function GetCompanyList(officeId) {
    var companyList = document.getElementById('<%= CompanyDropDown.ClientID %>');
    if (companyList.length == 0)
        PageMethods.GetCompanyList(officeId, OnGetCompanyList);


<asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true" />

Code behind:

public IEnumerable<CompanyMinimum> GetCompanyList(int officeId) {
    return (
        from c in Repository.Query<Company>()
        where !c.IsDeleted && c.TypeEnumIndex == (short)CompanyRelationshipType.Hotel
        select new CompanyMinimum() {
            id = c.Id,
            desc = c.Description

But at the call to PageMethods.GetCompanyList() in the first snippet, Chrome reports:

PageMethods is not defined

Can anyone see what has changed to prevent this from working?

Note: I've found similar questions but they all seemed related to this code not working in master pages or user controls, which isn't the case here.



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.

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:

    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.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.


Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us

©2020 All rights reserved.