Introduction
From MagicAjax.NET web site - "MagicAjax.NET is a free open-source framework, designed to make it easier and more intuitive for developers to integrate AJAX technology into their web pages, without replacing the ASP.NET controls and/or writing tons of JavaScript code. Just as a plug & play component."
Definition of AJAX
Asynchronous JavaScript And XML, or its acronym Ajax (Pronounced A-JAX), is a web development technique for creating interactive web applications. The intent is to shift a great deal of interaction to the web surfer's computer, exchanging data with the server behind the scenes, so that the entire web page does not have to be reloaded each time the user makes a change. This is meant to increase the web page's interactivity, speed, and usability. read mode
Thanks To
First and before we proceed, I'd like to thank the pioneer developer who brought this component to us, he is Argiris Kirtzidis, who first publish MagicAjax.Net as an article on CodeProject.
What is this article about
This article is about to show how to use MagixAjax.Net as plug & play component in ASP.NET Applications. Which saves time and improve the performance of your web applications.
Assumptions
This article assumes that you are familiar with ASP.NET and its controls as well as ADO.NET.
Also you may need to download the MagicAjax.Net from http://www.magicajax.net
Configure Your ASP.NET Application to be ready for MagicAjax.NET
- Copy MagicAjax.dll into your bin folder
- Modifying web.config:
The MagicAjaxModule should be registered in the system.web section of the web.config file of your application, like this:
<
httpModules>
<add name="MagicAjax" type="MagicAjax.MagicAjaxModule, MagicAjax" />
</httpModules>
MagicAjax will work with the default configuration options.
Create simple page & registering MagicAjax.Net controls on page
- Create a simple page.
- Add Reference to MagicAjax.dll to your project.
- A tag prefix should be registered for MagicAjax's controls namespace at the top of the page like this:
<%@ Register TagPrefix="ajax" Namespace="MagicAjax.UI.Controls" Assembly="MagicAjax" %> - Add the AjaxPanel Control
<ajax:AjaxPanel id="AjaxPanel1" runat="server"><%--Your Controls Gose Here --%></ajax:AjaxPanel> - Now add a DataGrid Control inside your AjaxPanel. You can do that using the VS.NET designer
Query your DataSource
DataSet the returns set of Products from Northwind database. Do that by any mean you'd prefer.
private DataSet GetDataSet()
{
SqlConnection conn = new SqlConnection(ConfigurationSettings.AppSettings["NWConn"]);
SqlDataAdapter adapter = new SqlDataAdapter("SELECT ProductName, UnitPrice FROM Products", conn);
DataSet ds = new DataSet();
adapter.Fill(ds);
return ds;
}
Implement Paging
Suppose you want to do paging on your DataGrid, implement the PageIndexChange of your DataGrid.
private void grdProducts_PageIndexChanged(object source, System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
{
grdProducts.CurrentPageIndex = e.NewPageIndex;
DataSet ds = GetDataSet();
grdProducts.DataSource = ds;
grdProducts.DataBind();
}
Also you may code your page load, something like the following:
private void Page_Load(object sender, System.EventArgs e)
{
if(!IsPostBack)
{grdProducts.DataSource = GetDataSet();
grdProducts.DataBind();}
}
Also you may would like to do sorting, edit and update of your data inside your gird. All this is supported, Just do it as you usually do. And after finishing, put your DataGrid or any other control inside and AjaxPanel just as plug & play, and watch the magic of The MagicAjax.Net.
Conclusion
At the time of writing this article, MagicAjax Release a major release of the component, it MagicAjax.Net 0.3.0. I'm sure you may find some bugs or features that may need improvements during working with the control. Just read the documentation that comes with the component, and have a log at the change log as well.
Also MagicAjax.Net support ASP.NET 2.0, so you can use it also in VS.NET 2005
Have fun with AJAX.

zohra zohraPosted Feb 28, 2008, 1:56 AM
Assalam..... Loooking for a sample code in C#.net for grid Specificaly to avoid postback in Grid for all operations ....Zor
vishakha ujjainkarPosted Jan 26, 2008, 8:12 AM
Hi I want complete introduction for ajax as i am new to it and havent learnt.can anyone tell me some sites to learn or tutorials.plz help. vishakha ujjainkar 9221339392 [email protected]
Dilipkumar DaveeditedPosted Aug 24, 2006, 4:58 AMEdited Oct 3, 2006, 6:15 AM
Keeping Datalist control inside Ajax control works fine. But I have following problem : I am having datalist control which have dropdown list in it's each row. I want to handle postback of dropdown control inside datalist. In normal case, without AJAX I can handle it easily by specifying handler. But, When I keep datalist control inside Majic AJAX, aplication crashes. Can anybody help me in this. Regards, Dilip.
SarojPosted Jul 14, 2006, 2:46 AM
Excellent ONe
Gayu DamseditedPosted Mar 27, 2006, 12:58 AMEdited Nov 12, 2006, 3:23 PM
This code works fine in my local system.But when i tried uploading the webpage in the server it shows the following error.pls help Object reference not set to an instance of an object. NullReferenceException: Object reference not set to an instance of an object.] MagicAjax.AjaxCallHelper.GetPageHiddenDictionary(Page page, String fieldName) +34 MagicAjax.AjaxCallHelper.Page_PreRender(Object sender, EventArgs e) +245 System.Web.UI.Control.OnPreRender(EventArgs e) +2066940 System.Web.UI.Control.PreRenderRecursiveInternal() +77 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1360