'PageMethods' is undefined

Discussion in 'ASP .Net' started by Robert Johnson, Jan 21, 2009.

  1. I have an ASP.NET 3.5 (+SP1) Web application on a clean image, with no beta
    versions of "Atlas" or the 1.1 Framework installed... XP Pro/SP3 + patches
    and updates.

    I'm getting the JavaScript error: 'PageMethods' is undefined when attempting
    to execute this line:
    PageMethods.ExecuteCommand(...)

    I have googled this a bunch, and most of the issues and associated
    resolution are nicely summarized in this small list:
    http://chiragrdarji.wordpress.com/2008/10/22/page-methods-is-undefined/

    .... but none of the issues presented there are relevant to me (or I have
    verified that things are as they should be with respect to those particular
    possible problems)... and I still am encountering the error.

    In brief
    1. I do have a ScriptManager with EnablePageMethods=true
    2. The IIS Web site's virtual dir is not configured for 1.1 (but for clr
    2.x)
    3. the Web.config files match (between my app and a working sample app)...
    has the WebServices section, etc...
    4. I'm *not* using a pre-release version of Atlas (never installed on this
    box)

    What else can I look at?

    I am fortunate to have a working example - same Framework version and all. I
    have compared Web.config and the entries match. The big difference is that
    the sample app is a Web site using the built-inWeb server, whereas my app is
    the Web Application project type that using IIS.

    Your suggestions are appreciated, as I'm feeling stuck on this one.
     
    Robert Johnson, Jan 21, 2009
    #1
    1. Advertising

  2. Here is the answer - for anybody researching this issue ('PageMethods' is
    undefined):

    I was getting that issue because my app didn't have any page method defined
    (i.e., a public static method with the [System.Web.Services.WebMethod]
    attribute).

    You can reproduce the issue (really, non issue when you understand what's
    going on) like this:

    1. Create a new ASP.NET Web app

    2. add a ScriptManager to default.aspx, and set EnablePageMethods="True"

    3. run the app and view the page source.
    You will see in the rendered html an *absence* of the following
    PageMethods.prototype = {...}

    4. Stop the app, then add a method to default.aspx.cs.
    Make the method static and public decorated with the
    [System.Web.Services.WebMethod] attribute.

    5. Run the app and view the rendered page source. This time you will see
    PageMethods.prototype = {...} in the page source.

    Apparently ASP.NET will not define the PageMethods in the client markup if
    there is no server-side page method to call. Makes perfect sense.

    -HTH



    "Robert Johnson" <> wrote in message
    news:e%...
    >I have an ASP.NET 3.5 (+SP1) Web application on a clean image, with no beta
    >versions of "Atlas" or the 1.1 Framework installed... XP Pro/SP3 + patches
    >and updates.
    >
    > I'm getting the JavaScript error: 'PageMethods' is undefined when
    > attempting to execute this line:
    > PageMethods.ExecuteCommand(...)
    >
    > I have googled this a bunch, and most of the issues and associated
    > resolution are nicely summarized in this small list:
    > http://chiragrdarji.wordpress.com/2008/10/22/page-methods-is-undefined/
    >
    > ... but none of the issues presented there are relevant to me (or I have
    > verified that things are as they should be with respect to those
    > particular possible problems)... and I still am encountering the error.
    >
    > In brief
    > 1. I do have a ScriptManager with EnablePageMethods=true
    > 2. The IIS Web site's virtual dir is not configured for 1.1 (but for clr
    > 2.x)
    > 3. the Web.config files match (between my app and a working sample app)...
    > has the WebServices section, etc...
    > 4. I'm *not* using a pre-release version of Atlas (never installed on this
    > box)
    >
    > What else can I look at?
    >
    > I am fortunate to have a working example - same Framework version and all.
    > I have compared Web.config and the entries match. The big difference is
    > that the sample app is a Web site using the built-inWeb server, whereas my
    > app is the Web Application project type that using IIS.
    >
    > Your suggestions are appreciated, as I'm feeling stuck on this one.
    >
    >
    >
    >
    >
     
    Robert Johnson, Jan 22, 2009
    #2
    1. Advertising

  3. Robert Johnson

    ktsang

    Joined:
    May 5, 2010
    Messages:
    1
    You need to make sure the webmethod you are calling is a static method
     
    ktsang, May 5, 2010
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. germ
    Replies:
    0
    Views:
    336
  2. Michael Nemtsev

    Consuming PageMethods from the external client

    Michael Nemtsev, Aug 1, 2007, in forum: ASP .Net
    Replies:
    0
    Views:
    424
    Michael Nemtsev
    Aug 1, 2007
  3. =?Utf-8?B?SmVycnkgQw==?=

    ajax pagemethods

    =?Utf-8?B?SmVycnkgQw==?=, Aug 9, 2007, in forum: ASP .Net
    Replies:
    2
    Views:
    479
    Walter Wang [MSFT]
    Aug 14, 2007
  4. Damien
    Replies:
    1
    Views:
    507
    gerry
    Aug 15, 2007
  5. George Ter-Saakov

    Pagemethods with AJAX

    George Ter-Saakov, Aug 28, 2007, in forum: ASP .Net
    Replies:
    1
    Views:
    1,466
    George Ter-Saakov
    Aug 28, 2007
Loading...

Share This Page