Thursday, July 14, 2005

The Power of Panels in ASP.NET

It is fairly common that it takes several pages to be presented to the user to complete a single logical task within a web application.

Say you have a collection of free email newsletters that you want to offer to your site visitors. If a visitor clicks on the link to select one or more newsletters, you may well present:

[Screen 1] a checklist of the newsletters to choose from with a Submit button, then

[Screen 2] a list of just the newsletters selected with a confirmation button, then

[Screen 3] a printer friendly listing of the selected newsletters along with information on how to change or cancel subscriptions and a nice thank you for subscribing to your site newsletters.

Prior to ASP.NET, you likely would have written these as three separate ASP pages; Screen 1 posts to Screen 2 which posts to Screen 3. Easy enough, but it certainly cluttered up the folders on your web server and tracking logic errors was more difficult across three separate source files.

Now with ASP.Net, all three screens can easily be coded into individual panel objects, all within the same .ASPX web page. The code-behind file makes the needed panel visible and sets the visibility of the other panels to false. The user still sees three different screens in sequence but coding is greatly simplified since it is all contained within a single .vb or .cs code-behind file.

I have used this technique in several web applications and it works great. The invisible panels are not included in the final page to the browser so the download times remain tight. I hope you find this tip very useful.

Joe Kunk

No comments: