Pages

Thursday, July 17, 2008

Working with Anthem.NET

Anthem.NET is an open source cross platform AJAX toolkit for the ASP.NET 1.1 and 2.0 development environment. Anthem.NET controls library has built in AJAX functionality and all credit goes to Jason Diamond who had the great idea to encapsulate AJAX functionality into regular Web Form controls. By using the Anthem.NET controls we can get rid of the typical postbacks.

All you have to do is download the Anthem.NET project source code from the following URL:

http://anthemdotnet.com/downloads.aspx

This source code includes different projects for VS.NET 2003, 2005, Examples and Extensions.

There are multiple ways to include Anthem.NET into your project:

1) You can add a reference to your project by browsing to the Anthem-2005 (if we take an example to integrate the Anthem.NET in our VS.NET 2005 project) and open the file named 'Anthem-2005.csproj'

2) Alternatively you can seperately compile the Anthem-2005, generate the dll, copy and place it in your bin directory.

Now what happens if we want to use those Anthem.NET controls to our ASP.NET Web Application.

First of all you have to register that Anthem assembly to your page using

<%@ Register TagPrefix="anthem" Namespace="Anthem" Assembly="Anthem" %>

Add an anthem:Button to your page:



Add a label to your page that would be used to show the current time without a postback whenever the above button is clicked



The attribute 'AutoUpdateAfterCallBack="true"' updates the control after every callback

Now add an event handler attribute for button's click as you do with your normal ASP.NET Button



Do necessary coding in the event handler

void btnDisplayTime_Click(object sender, EventArgs e)
{
lblDisplayTime.Text = DateTime.Now.ToString();
}

By running your web application you can see the result that the lable will be updated without having any postback. Working with Anthem.NET is as easy as your normal ASP.NET controls library.

There is a problem that sometimes when you want to use Response.Redirect with Anthem.NET Controls, it doesnt work, Jason Diamond has given a way around for this problem.

You can use the following line of code in order to change the location of window.

Anthem.Manager.AddScriptForClientSideEval("window.location = 'http://www.google.com';");


Waiting for your comments on this article

No comments: