Atlas:UpdatePanel + Template = Really Darned Kewl

I must say that ASP.NET Atlas, Microsoft’s free Ajax framework is pretty cool. Far and away my favorite feature is that it allows me, a Javascript challenged C# head, to build really slick, Ajaxy apps without leaving my server-side comfort zone. All that needed be done was write the application so that it worked within the normal ASP.NET lifecycle, events and parameters. Then slap some Atlas:UpdatePanels in there and let the framework do its thing.

Or so I thought. I tried to include those UpdatePanels in a templated control, such as a Repeater. And Atlas go boom. Now, this was not an insurmountable problem. One could always surround the entire repeater in an update panel. Or go back to classic, non-Atlas methods.Or actually learn Javascript and make your own plumbing. None of which are very appealing options.

Conveniently, the Atlas team also saw this as an fix-worthy issue. And, on 30 June, they released yet another CTP—creatively called the “Atlas” June CTP—to the public. It has a number of tweaks and bug fixes, one of which is near and dear to my heart:

UpdatePanels can be added to a page dynamically throughout the page lifecycle, including UpdatePanels inside templates. UpdatePanels now also work inside WebParts, and WebParts can be inside UpdatePanels.

So, I worked up a little demo of how handy the new functionality is. And, by inference, how cool Atlas can be.

Scenario: You have a list of contacts with four fields: Id, FirstName, LastName and Email. It is required that one cannot see an email address without clicking on a link instructing the application to show that address. An example of the dataset in Xml is posted at the end of this post for reference.

Now, one can go after this using two methods. First, one can rely upon a traditional postback and a full page refresh. Or one can embrace Web 2.0 and get their Atlas on. The really slick thing is that both methods could use the exact same codebehind file [ok, not exactly—you will need to change the class name to match your CodeFile reference in the .aspx file]. It looks like this:

But, what if your client demanded that his site be Ajax enabled? It is disturbingly easy—just add a little bit of Atlas plumbing and an update panel. Oh, and don’t forget the Atlas:UpdateProgress so you can justify the bill.

The first thing to note above are the new Atlas:SomeControlName tags. The ScriptManager runs the show; it is required to “Atlas enable” a page. The UpdateProgress control is a visual flourish—it allows one to tell the user that an update is in progress, much like the “LOADING” one sees in the top-right on Gmail.

That leads us to the Atlas:UpdatePanel. This is a very slick control that lets one allow a page to be partially rendered and fire back updates based on registered events. In this case, we provide a template—containing our LinkButton and the HyperLink it interacts with—and a single Trigger. This trigger is what Atlas uses to fire off the update. And a panel can have multiple triggers. In our case we needed but one—our LinkButton’s click event. And, as the code sample shows, that event behaves nearly identically to a standard, full-page postback.

Zero to Web 2.0 in 6.4 minutes. Without writing one character of Javascript nor modifying your C#.