News

ASP.NET AJAX Under the Hood

Scott Cate
Scott Cate

The VSLive! San Francisco 2007 session by Scott Cate on Microsoft's ASP.NET AJAX would have been standing-room only, except there wasn't room available to stand. Over 200 attendees were crammed into the conference room, making it one of the most popular breakout sessions at the event. Cate didn't disappoint the crowd, using only three content-free PowerPoint slides and five minutes before he drove directly into the code.

The key to ASP.NET AJAX on the client, according to Cate, is the use of the UpdatePanel control. By wrapping any control with the UpdatePanel, you make its data available to asynchronous updates. If the UpdateMode property of the UpdatePanel control is set to Always, then the UpdatePanel control's content is updated on every postback that originates from the page. This includes asynchronous postbacks from controls that are inside other UpdatePanel controls and postbacks from controls that are not inside UpdatePanel controls.

Cate illustrated this principle using a DataGrid control in an application. He wrapped a DataGrid control with an UpdatePanel in an ASP.NET 2.0 application and demonstrated that any updates to the grid did not require a refresh of the entire page. Rather, the update was processed asynchronously back to the server and the value alone was refreshed on the page.

You can use multiple UpdatePanel controls to update different page regions independently. When the page that contains one or more UpdatePanel controls is first rendered, all of the content in the UpdatePanel controls is also rendered and sent to the browser. On subsequent asynchronous postbacks, the content of each UpdatePanel control might not be updated, depending on the panel settings and on client or server logic for individual panels.

You can illustrate this principle in a sample ASP.NET 2.0 page by taking two identical controls and wrapping one of them in an UpdatePanel. If you make the same change to both controls, the control using the UpdatePanel updates more quickly and seamlessly, without a page update. The other control requires a full page refresh, no matter how trivial the change.

The popularity of Cate's session says a lot about the growing popularity of AJAX among developers in general, and Visual Studio developers in particular. AJAX, which allows asynchronous updates through the use of scripting, is rapidly becoming a standard for usability in Web applications. Microsoft's ASP.NET AJAX framework provides you with an easier way of achieving this standard in Visual Studio -- forget about manually writing scripts.

About the Author

Peter Varhol is editor in chief of FTPOnline. (The parent company of FTPOnline, Fawcette Technical Publications, Inc. was acquired by 1105media in December.)