ASP.NET and AJAX: So Freaking Easy (Part 1: Setting Up)
The easiest way to create an AJAX-enabled .NET site is to first download ASP.NET AJAX (it’s free). After you’ve got it installed, in your VS2005, go to Create New Project > (Web) > ASP.NET AJAX-Enabled Web Application and create your project. Yep, that’s it.
Oh, how do you use it? Well, Microsoft has introduced a concept called UpdatePanels which delineate what content is getting “AJAXed.” But before you do anything, you have to add a “ScriptManager” control right under your <form runat=”server”> tag. If you use templates or master pages, you can usually just add this there and not worry about it. Anyways, after you’ve added your script manager, go ahead and pick a section of your page you want to update without refreshing the whole page. When you’ve done this, wrap that section in a <asp:UpdatePanel id=”yourID” runat=”server”></asp:UpdatePanel> tag. This tells the server which section you wish to update “asynchronously”, meaning separate from the rest of the page.
After you’ve surrounded the section with your update panel, you’ll need to include just one more tag before you’re good to go: <ContentTemplate></ContentTemplate>. This goes after the opening <asp:UpdatePanel> tag and below the respective closing tag with all your content between it. The reason you need this is because there are more advanced features and tags you can include within your update panel that aren’t in your content, but they aren’t necessary for just starting out.
And that’s it! Go ahead and hit your pagination or sort button inside that section and see what happens. Pretty sick, huh?
If you have an existing application that isn’t AJAX-ready and you want to make it so, there are a few more steps you need to take in the preparation stage, but implementation is, of course, the same. I can go into it if someone posts here that they want me to (I just did it with my site! Really simple).
Has anyone had any problems with .NET/AJAX implementation?