Search code examples
c#asp.netpagemethods

PageMethods returning undefined result?


I have a very simple call to a PageMethod. When I step through my PageMethod in my .cs file, the value looks as expected. However, on the client side I get an undefined result. Any ideas? This should be horribly simple.

Here is my js: (EnablePageMethods="true" in my ASPX page)

function test() {
    alert(PageMethods.MyMethod("Joe Blow"));
}

And here is my C#:

public partial class test : System.Web.UI.Page 
{
    [WebMethod]
    public static string MyMethod(string name)
    {
        return "Hello " + name;
    }
}

Solution

  • Check out the following screencast. It explains how to call the PageMethods using JQuery:

    http://www.highoncoding.com/Articles/430_Calling_Page_Methods_Using_JQuery_and_Returning_JSON_Result.aspx