LB.
LB.

Reputation: 14112

jQuery AJAX Post to ASPX page or ASHX Handler

I have a question about doing a POST to an ASPX page vs posting to an ASHX handler or web service?

When would you use an ASPX page to handle the ajax request versus using a handler ?

I'm asking this because I am wondering if it is worthwhile to even go through the ASP.NET Page Life Cycle when all we are doing is returning data via the Response object.

any ideas?

Upvotes: 0

Views: 1299

Answers (1)

Gary.S
Gary.S

Reputation: 7131

If you are using AJAX to post to a method on the ASPX page then typically the method will look like:

[WebMethod]
public static string AJAXMethod(string arg)
{
    return "stuff";
}

This does not go through the page life cycle as it is static and no postbacks occur. That said, to answer your question "it depends". If the method is something that may now or in the future be used by multiple pages than ASHX or even WCF may be the route you want to take. If however the method is page specific and you expect it to remain so, then putting the web method on the page may make sense.

Upvotes: 2

Related Questions