SingingEels : Development Community & Resource

Login

Articles

  • ADO.NET (2)
  • ASP.NET (31)
  • LINQ (4)
  • Security (2)
  • Silverlight (2)
  • SQL (7)
  • Standards (5)
  • WCF (1)

Syndication

  • Articles RSS
  • Blogs RSS

Contribute

  • Our Authors List
  • Member Sign-Up
  • Suggestions Box

ASP.NET AJAX - Things To Know

(May 31 2007 - 09:14:52 AM by Timothy Khouri) - [print article]

Unless you've been hiding under a rock for the past few years you probably are at least somewhat familiar with ASP.NET AJAX. There are a few things though that you might not realize. We will discuss 1) why ASP.NET AJAX is so popular, 2) what are some potential dangers that you should be aware of and 3) how you can get started using ASP.NET AJAX.

1) ASP.NET AJAX - Beautiful

The term AJAX (Asyncronous JavaScript and XML) is broadcasted all around the internet, and can be found associated with many programming languages. There are PHP extensions, JavaScript snippets, Ruby examples and HTML purists all boasting their skills with AJAX. However nothing compares to the power of the .NET framework, and in particular, ASP.NET AJAX (formerly known as "Atlas").

ASP.NET AJAX is easy to use, object oriented and snaps right into Visual Studio and your .NET web applications. With very little code you can "mash up" your entire site, or small portions of your site giving a smooth and clean user experience. This code will show how easy it is, and will clearly demonstrate why ASP.NET AJAX is so popular.

Here is our simple web application that will display the current time from the web server into a TextBox.

<!-- Here is the ASP code -->
<form id="MainForm" runat="server">
   <div>
       <asp:Button ID="UpdateButton" runat="server" Text="Update" />
       <asp:TextBox ID="TimeStampTextBox" runat="server" />
   </div>
</form>
// Here is the C# code-behind.
protected override void OnInit(EventArgs e)
{
   this.UpdateButton.Click += delegate
   {
       this.TimeStampTextBox.Text = DateTime.Now.ToLongTimeString();
   };
}

If you were to click on the "UpdateButton" then, like all browsers do, you would post-back to the server, your browser would likely flicker a little bit and then the entire page would be re-rendered and you'd see the following results:

An update Button and TextBox for an AJAX example

Watch how easy it is to convert this code to start using ASP.NET AJAX. We won't have to change any of our C# code-behind, we don't have to learn XML. All we need to do is tell ASP.NET what should be automatically converted to asyncronous code. Here's how:

<form id="MainForm" runat="server">
<!-- Step 1: Add a "ScriptManager" and turn on "PartialRendering" -->
<asp:ScriptManager ID="ScriptManager" runat="server" EnablePartialRendering="true" />

<!-- Step 2: Wrap our existing code in an "UpdatePanel" -->
<asp:UpdatePanel ID="TimeStampPanel" runat="server">
   <ContentTemplate>
       <asp:Button ID="UpdateButton" runat="server" Text="Update" />
       <asp:TextBox ID="TimeStampTextBox" runat="server" />
   </ContentTemplate>
</asp:UpdatePanel>
</form>

This is so easy there's no question why so many people are running to ASP.NET AJAX. There are cautions however that need to be considered. We'll cover that in this next part.

2) Potential Dangers You Should Be Aware Of

Usually any great new technology that comes out becomes over used, or used incorrectly due to a lack of understanding of the dangers. For example, dynamite is a great way for engineers to blast through mountains as they are building rail-roads. But if people started using dynamite as a candle to light there way to the kitchen at night, their results may be unexpected.

Likewise, when web designers want to make their site attract more visitors, they may think that slapping AJAX all around will boost traffic to their site. More than likely they are killing their site. The reason for this is because a lot of their content that used to come directly by going to the site or clicking on links is now only provided by nifty AJAX timers and other asyncronous ways of transfering data.

Yes it looks cool, but Google (and other search engines) won't process your AJAX. It's the same thing as making your site one giant image... just because you have "words" on the image, search engines won't be able to see any content and your site will drop in worth. So make sure that your site degrades nicely back into regular old HTML.

3) How You Can Get Started Using ASP.NET AJAX

To get started using ASP.NET AJAX, you'll first want to download the installer from Microsoft that will add the extensions to Visual Studio. You don't *need* these extensions in Visual Studio, but it makes it easy to start a new AJAX site. They include the DLLs and a Web.config file that has the necessary configuration settings.

You can use the code from this article, or follow any tutorials from ajax.asp.net. There is a lot more to ASP.NET AJAX though that this article doesn't go into; consuming web services is one example. That will be discussed in a follow up article very soon.

You must be logged in to add comments. If you have not already done so, you can create an account here. If you already are a member, you first need to login before you can comment.

Developer / Architect / Author

People to Follow

Experts in the categories related to this article.

  • Jonathan Carter

Related Blogs

These are the most recent blog posts related to this article.

  • How to Handle "Side Content" in ASP.NET MVC
  • LINQ to SQL - Am I Hitting The Database?
  • ASP.NET MVC - Issue with CSS Class Name on ActionLinks
  • Site Updates, Bug Fixes and Syndication in .NET 3.5

Related Ads

SingingEels.com as of Aug 20 2008 - 08:58:27 PM - (0.140625)