Update Panel .NET

Exploring Microsoft ASP.NET AJAX and jQuery

How to invoke ASP.NET Page Methods using jQuery

with one comment

Why do I want to invoke ASP.NET Page Methods using jQuery?

  • I do not want the ScriptManager to generate any proxy code in my page source, i.e. set EnablePageMethods to “false”.
  • I want to make the call synchronous! (N.B. You should avoid making synchronous calls!)

Show me the code:

$.ajax({
    async: true, /* set this to false to make a synchronous call */
    contentType: "application/json; charset=utf-8",
    data: Sys.Serialization.JavaScriptSerializer.serialize({ arg1, arg2, etc... }),
    dataType: "json",
    type: "post",
    url: "application_path/page.aspx/page_method_name",
    success: function(result) {
        // Insert your success handler code here.
    }
});

I am assuming the Microsoft AJAX Library is included on the page, and I am using Sys.Serialization.JavaScriptSerializer.serialize to prepare the page method call arguments into JSON.


Written by tzkuei

July 2, 2009 at 12:51 pm

Posted in ASP.NET, jQuery

One Response

Subscribe to comments with RSS.

  1. You never know when synchronous call may be required. My present love of effort requires me to enhance lookup so that it dynamically populate sql parameters with form fields’ values. I need to use synchronous so that I can update the sql in session variable, and thereupon invoke call to the lookup dialog.

    Thanks for this barebone wonder.

    Ranjit Kumar

    March 10, 2010 at 12:38 am


Leave a Reply