Using the Ajax.NET Framework

What's New?

Featured CoDe Magazine Content

LINQ by Yair Alan Griver

Using the Ajax.NET Framework

Introduction

The Ajax.NET Framework is a simple-to-use framework that wrapps up most of the plumbing of using Ajax.

There only a few actions you have to take to empower your application with the Ajax.NET framework

  1. Make reference in your project to the Ajax.NET Framework
  2. Add an httpHandler to your web.config
  3. Register your page as an Ajax.NET Framework page
  4. Decorate your methods with the [Ajax.AjaxMethod()]
  5. Call your method in JavaScript using the type name of your page

Here are some examples:

1) Set Reference

No example necessary.

2) HttpHandler

Provide a way for the Ajax.NET Framework to look at each request and determine if it need to do anything.

<httphandlers>
	<add verb="POST,GET" path="ajax/*.ashx" type="Ajax.PageHandlerFactory, Ajax" />
</httphandlers>
                

3) Register Page

You register with the type of the page you are registering.

Ajax.Utility.RegisterTypeForAjax(typeof(_default));
                

4) Use the Ajax.AjaxMethod Attribute

Here is a sample method.

[Ajax.AjaxMethod()]
public TaskCollection GetTasks()
{
    return WebAppConfig.Tasks;
}
                

5) Use the Page Type Name in JavaScript

You call the function in JavaScript using the type name of your page as the object. You may optionally pass in a parameter that will use a call back method when the action is complete.

function GetTasks()
{
    _default.GetTasks(GetTasks_CallBack);
}

function GetTasks_CallBack(response)
{
    if(IsValidResponseValue(response))
    {
        LoadTasks(response.value);
    }
}
                

Support Provided by:

comments powered by Disqus