Monday, November 3, 2008

Ajax

Introduction
Asynchronous JavaScript and xml (AJAX) is now the need of the new generation websites. In the asp.net using AJAX is very easy. We just place few line codes in the web.config file and start using Ajax tags. But you should download Ajaxtoolkit first from the following Microsoft link…

http://www.microsoft.com/downloads/details.aspx?FamilyID=ca9d90fa-e8c9-42e3-aa19-08e2c027f5d6&displaylang=en

Requirements:
(1) Microsoft .NET Framework Version 2.0,
(2) IE 5.01 or later
(3) Windows 2000; Windows Server 2003; Windows Vista; Windows XP
After download this exe you will get the additional option in your .net toolbox is Ajax Extensions.

Now two ways to use ajax
(1) Create a new ajax enabled web site. File->new ->ajax enabled web site
OR
(2) Changes made in your existing asp.net2.0 website.
You must add the following lines in your web.config files.
Add these lines in

--httpHandlers--
--remove verb="*" path="*.asmx"--
--add verb="*" path="*.asmx" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"--
--add verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" validate="false"--
--httpHandlers--
--httpModules--
--add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"--
--httpModules--

If you think why I add these lines in you web.config file then the answer is these lines you can find in you system
C or other system directory \Program Files\Microsoft ASP.NET\ASP.NET 2.0 AJAX Extensions\v1.0.61025\web.config
If you don’t do that, then you will get the ‘sys is undefine’ javascript error. And your ajax will not work fine.
So, cheer up, now your application is ready to implement the ajax in .net 2.0. First place a “script manager” and then a “update panel”. Now Any control in the update panel if request to server, then only the part within the update panel will submitted to the server. This is very useful when your page is frequently postback.

Ref:
http://www.afteredge.com/post/UpdatePanel-Extender-for-ASPNET-AJAX.aspx
http://www.asp.net/AJAX/Documentation/Live/tutorials/UsingUpdatePanelControls.aspx
http://www.asp.net/AJAX/Documentation/Live/overview/AsynchronousLayerOverview.aspx

download here!