views:

242

answers:

1

We're redevloping a major section of our website and rather than use a 90k AJAX file I'd rather use a 19K jquery script.

I've seen the following articles;

The thing I don't get is how to do a postback to a specific method in either the code behind or another class.

I know in ASP.NET-MVC I can post back to a controller / action. How do I call a particular method in WebForms?

Something along the lines of; $.post("class and action", ( param:value}......

Any thoughts, code etc???

+2  A: 

It is very easy to call specific methods in code-behind. Here is nice article with all the details by Dave.

Simply declare a method like this:

 [WebMethod]
  public static string GetDate()
  {
    return DateTime.Now.ToString();
  }

This is all you need in jQuery:

$.ajax({
  type: "POST",
  url: "PageName.aspx/MethodName",
  data: "{}",
  contentType: "application/json; charset=utf-8",
  dataType: "json",
  success: function(msg) {
    // Do something interesting here.
  }
});
TheVillageIdiot
Dang! Blocked by our company internet filter which blocks most useful development sites. Will check from home tonight thank you @TheVillageIdiot. Great name btw.
griegs
That is awesome. Thank you very very much.
griegs