views:

289

answers:

1

Using query ajax to call a webmethod in an ASP.NET page works well if the HTTP request is a POST. If a HTTP GET request is used the Page_Load event runs instead of the webmethod. Any ideas?

Here is the Ajax

$.ajax({
        type: "GET",
        url: "http://local.proleaguesports.pagefad.com/AjaxTesting.aspx/receivermethod",
        data: "{'test':'MyName'}",
        contentType: "application/json",
        dataType: "json",
        success: mycallback,
        error: handler
    });

AND here is the code behind in C#

public partial class AjaxTesting : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        Response.Write("Page_Load runs instead of the receivermethod below");
    }

    [WebMethod]
    [ScriptMethod(UseHttpGet = true)]
    public static string receivermethod()
    {

        return "test received";

    }
}
A: 

You might consider moving your webmethods into a separate web service/asmx. I heard somewhere that calling a webmethod in an aspx causes the entire page to be reloaded, though I can't find a confirming reference for that at the moment.

David Lively
No it doesn't. I have a few web methods that work just fine and don't reload the page.
krishna
I've just set a breakpoint in the page_load method of a page that has several webmethods. Calling the webmethod does, indeed, trigger Page_Load(), and I assume everything else that implies.
David Lively