First read Setup and Ajax Functionality.

Web.Ajax supports Inversion of Control, allowing you to put your Ajax methods into interfaces.
You can map interfaces to implementations in your Global.asax allowing you to write testable Ajax methods rather than relying on static methods.

using Web.Ajax;

public interface IAjaxMethods
{
    [Ajax(Name="Ajax.SampleMethod")]    //The Name identifies the method on the client
    int SampleMethod(int a, int b)
}

public class AjaxMethods : IAjaxMethods
{
    public int SampleMethod(int a, int b)
    {
        return a*b;
    }
}

In your Global.asax
public class Global : System.Web.HttpApplication
{
    protected void Application_Start(object sender, EventArgs e)
    {
        Web.Ajax.InversionOfControl.Container.Instance.Map<IAjaxMethods, AjaxMethods>();
    }
...

In your page class you register the interface containing the Ajax methods
using Web.Ajax;

public partial class Default : Web.Ajax.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        Ajax.RegisterAjaxMethods(this, typeof(IAjaxMethods));
    }
}

Last edited Jan 12, 2013 at 2:07 PM by dpembroke, version 15

Comments

No comments yet.