Free Online Articles Directory
18.11.2008 Sign In Register Hello Guest
Email:
Password:
Remember Me 
forgot your password?


Optimizing Your Asp.Net Pages for Faster Loading and Better Performance.

Author: John Belthoff Author Ranking Blue | Posted: 27-04-2006 | Comments: 0 | Views: 1,438 | Rating:  (94) Article Popularity - Blue (?) Got a Question? Ask.
Sign Up Now!

If you read the internet and all of the websites dedicated to Asp.Net you will inevitably read about the wonders of the DataGrid, DataList, and Repeater controls. While each of these has its place, if you are only displaying data there is a much faster and more efficient means to do so.

Let's say you have a page that displays articles based on a query string. Take my article pages for instance. Each article is stored in a database and displayed on the page based on the unique id of the article as stored in the database.

A normal asp page execution procedure goes something like this. The code queries the database based on the Article I.D. and then brings back that information to the page where you display it in the fashion that you would like. This is a fairly straight forward approach with asp and is done all the time.

So how do we speed up our asp.net pages?

Number 1: Use Asp.Net Caching!

This is a no-brainer, and I won't go into the brilliance or details of asp.net caching here because at the time of this writing Google has 2,780,000 articles on the topic. Basically instead of querying the database each time the page is loaded you only query the database once and load that result into the system cache. Subsequent calls to load the page retrieve the data from the cache as opposed to the database which gives you an instant and considerable performance boost. You can then set the cache for how long the cache should store the information as well as many other features. If you are not using the cache, you should be whenever possible!

Number 2: If possible, do NOT use the standard Asp.Net controls.

That's right. The standard asp.net controls are designed for rapid development and not page performance. They allow you to design pages that grab and display data very quickly but their actual performance suffers because of the extra overhead which is there for ease and speed of development time and not page execution speed.

Instead, create either a User Control or even better yet a Web Custom Control which is by far the fastest performance wise and really quite easy to create and use.

Number 3: Use an SqlDataReader or even better yet use a set based command for Sql Server data retrieval and simply execute that one command against the database.

An asp.net SqlDataReader is a fast forward only datareader that closes the connection after it reads the last set of results. Now for my article pages we are only returning 1 particular result. In this case we would opt for the set based command. If you had more than 1 result returned, in your table of contents for instance, you would use the SqlDataReader because you are returning multiple sets of results.

Set based commands are stored procedures that bring back data through parameters as opposed to a result set which then in turn needs to be looped through to obtain your data. So instead of writing your stored procedure like the following which brings back 1 result set:

Select Title, Body, Author
From Articles
Where ArtID = 215

We can write it using a set based command like this.

Create Procedure mysp_GetArticle

@Title varchar(200) Output,
@Body varchar(8000) Output,
@Author varchar(500) Output

As

Select @Title = Title, @Body = Body, @Author = Author
From Articles
Where ArtID = 215

GO

The above query will return only the three parameters called for and not a result or record set so you don't have to then walk through the returned record set that has only 1 result in it anyway. This second little process of work decreases your performance so you should avoid it whenever possible. Combine this technique with the asp.net cache.

Number 4: Use Classes and ArrayLists as opposed to returning an SqlDataReader.

Create a class and then if there are more than one set of results store those results into individual instantiations of that class. Finally store each of those classes into an ArrayList. You can then store only that ArrayList into the asp.net cache. So instead of getting the results back from a SqlDataReader when loading your page you get them from the ArrayList which is stored in the cache. Nice huh?

Finally... you want to incorporate all of these techniques into your final results which would be performed in the following manner and sequence.

On the first time the page loads, query the database and return all of your data storing it into individual classes. Then store each of those classes into an ArrayList. If you only have one single result you may store only the class into the cache. Then take your ArrayList and store it into the cache.

Next create a Web Custom Control and pass the cached ArrayList to the custom control and loop out your data using the HtmlTextWriter which is very fast. Remember each subsequent call to load the page will be called from the cache which stores your ArraList of classes or your single class.

Certainly it takes a significant amount of additional coding to do it in this fashion, especially when you take proper error handling into consideration, but if you follow this approach your pages will be screeching fast, you will immediately notice the difference, and your asp.net pages will execute in the proper sequence - Data handling in the PageLoad function and the html display in the PageRender function.

Further, you will be glad you did and so will your visitors.

Happy Programming!

Rate this Article: Current: 5 / 5 stars - 1 vote(s).

Article Source: http://www.articlesbase.com/programming-articles/optimizing-your-aspnet-pages-for-faster-loading-and-better-performance-24825.html

Print this Article Print article   Email to a Friend Send to friend   Publish this Article on your Website Publish this Article   Send Author Feedback Author feedback  
About the Author:

John Belthoff is an avid web developer who writes about Asp.Net in his spare time. He owns a Windows Asp.Net, Asp Web Hosting Company where you can contact him about hosting your website/blog or just to learn more.

Submitting articles has become one of the most popular means to drive traffic to your website and promote yourself and your business. Join us today - It's Free!

Article Comments

Comment on this article Comment on this article
Your Name
Your Email:
Comment Body
Enter Validation Code: Captcha


Related Articles

How to Choose From Viewstate, Session, Application, Cache, and Cookies
By: Ahmed Siddiqui | 09/06/2008 | Programming
This article gives you a brief description and comparison on different state options available in ASP.NET

Eboostr: Readyboost for Windows Xp
By: Steve Bralovich | 04/02/2008 | Computers
eBoostr betters the speed of a PC or laptop without having to upgrade its internal components or the operating system. Using USB flash pen memory drives or flash memory cards, permits Windows XP to access hard drives to a much lesser extent. This results in upgraded performance and responsiveness of Windows XP and all running applications.

Goal Setting Time! Where Do I Start?
By: Marnie E. Green | 18/09/2005 | Management
See goal setting as the opportunity to list the classes the employee will attend for the coming year. And, while learning goals are appropriate, the goal setting process can.

Web Languages: Php Vs. Asp.net
By: Kevin Jordan | 10/11/2006 | Programming
While the average web developer has a lot of options these days. It's really more of a bi-partisan system between ASP.NET and PHP, the rest being just independents. The battle rages between the supporters of the two languages, with no clear winner every coming out. While both can be used to complete the same project, it really depends on what you're looking for: price, speed, security, etc.

Url Rewriting in Asp.net With Sample Project
By: joggee | 27/06/2008 | Programming
URL rewriting is the process of intercepting an incoming Web request and automatically redirecting it to a different URL. To understand completely follow below link http://msdn.microsoft.com/en-us/library/ms972974.aspx In this article I am going make a simple example which will take only few minutes and you will learn how to achieve URL Rewriting. I believe developer doesn’t have much time to read a complete article of 20 pages.

Internet Cleaners Tools
By: IC | 13/05/2007 | Technology
Did you also know that unwanted images, banners, pictures and content that exists on websites you visit, can be downloaded on your PC without your knowledge.?

Drivers Under 25 in The Lone Star State Face a More challanging Time Brushing off Traffic Citations
By: Joe Gerstl | 15/09/2005 | Law
Defensive driving video rentings & will increase the amount of road tests distributed by the State Department of Public Safety. Beginning Sept. 1st 2005, a drivers.

Lasik Eye Surgery - What Will you Gain From Having the Operation?
By: Ron Hel-Or | 28/10/2006 | Health
Many people question the necessity of Lasik eye surgery. Though not a life-saving operation, this surgery can immensely improve the lifestyle of the people who take it. Read The article to find out more.

Got a Question? Ask.

Ask the community a question about this article:

Frequently Asked Questions

Charley Jason Hall of Pigeon Forge, TN
By: Fred | 22-09-2008
Where is Charley Jason Hall of Pigeon Forge, TN performing now?

Difference between caterpillar 320 and case 210B ...
By: farmerbill21 | 19-09-2008
difference between caterpillar 320 and case  210B excavators

What size tabs can you add to a maxum 2900 to ...
By: Dale | 15-09-2008
What size tabs can you add to a maxum 2900 to increase lift and reaching plane. I have the single 454 bIII and have 12x9 tab;s/ I am looking at the 30x9 upgrades but wonder about handling and if in fact will the new 30" tabs fit

What is a good age to start placing your dog in the show ring?
By: Sherry | 11-09-2008
I have a 7 month Golden Retriever & am planning on showing him in obidience training. we are in training now I am not sure what is the age to be able to enter a show ring with him???? Thank-you. Sherry Hoffmann

How will a bad catalytic converter affect the ...
By: carqueations | 09-09-2008
how will a bad catalytic converter affect the performance of a 96 ford explorer?

Why is there a brown line in the bowl at the water ...
By: Joy | 07-09-2008
Why is there a brown line in the bowl at the water level and streaks of discolored (brown) leaking from the rim?  

Q&A Powered by:
Powered by Yedda 

Latest Programming Articles

Cool Desktop Wallpapers
By: Danny | 18/11/2008
Cool desktop wallpaper is accomplishments arrangement that displayed in the computer operating system. The wallpapers usually be acclimated in JPEG, BMP and GIF book formats. That wallpaper can be acclimated with Microsoft Windows, Linux and Macintosh Mac OS. Each adviser can be altered requirements, alike admitting wallpaper images advised for accepted monitors can be scaled up or bottomward to the fit size. Those are accessible on the internet for free. Some categories of wallpapers are a

Tips for Buying Software Online
By: Daniel Jowssey | 17/11/2008
Buying software online not only helps save the planet, it also has other benefits, including: * Ease and Simplicity. You can purchase software in your underwear at 4am if you really want to. Shopping online doesn’t have to be done within regular business hours, nor do you need to look your best to do it. It’s also easy to shop around for the best prices and takes less time than driving to the shops.

Mvc Design Pattern
By: TuVinhSoft .,JSC | 14/11/2008
Model-view-controller (MVC) is an architectural pattern used in software engineering. In complex computer applications that present a large amount of data to the user, a developer often wishes to separate data (model) and user interface (View) concerns, so that changes to the user interface will not affect data handling, and that the data can be reorganized without changing the user interface.

Advantages of Low Cost Contract Programmers in Freelance Programming
By: Joanna Gadel | 12/11/2008
It observed that web industry is getting tougher thus the necessity of freelance contract programmer is required for developing more effective website with flexible features. This article states the fruitful advantages of freelance programmers in contract programming.

A Guide to Cnc Kits
By: Martin Applebaum | 09/11/2008
CNC kits are a way in which to construct your CNC machine. This article will provide some information on these machines.

A Guide to Cnc Tube Bending Machines
By: Martin Applebaum | 08/11/2008
Are you familiar with a CNC tube bending machine? This article will shed some light on the main function and components of this machine.

Ways to Hire Dedicated Php Programmers
By: Jucick | 08/11/2008
It’s not at all easy to hire dedicated PHP programmers unless you know where and how to find them. Whether you need to fix, update or enhance your website you naturally want the job done quick and right.

Top 4 Reasons Why Addressing Web Accessibility is Important
By: Matt Cave | 05/11/2008
There are very high chances that web accessibility is more important to the performance of your web site than you realize. Article takes a look at the top 4 reasons why it would be important to address the issue of web accessibility.

More from John Belthoff

The Art of Playing Jazz Guitar - A True Preparation Primer Part 2
By: John Belthoff | 17/04/2006 | Art & Entertainment
In part 1; we discussed various metronome techniques to advance our awareness, concentration, feeling, and broaden our minds while practicing. This article will go into what we should be practicing and thinking when using those techniques.

Upgrading to ASP.Net 2? Why your website might stop working when you do.
By: John Belthoff | 01/04/2006 | Advertising
Asp.Net version 2 was just recently released by Microsoft and contains a feature rich set of classes. However if you are thinking about hosting your asp.net 2 site on a shared hosting environment there are a few considerations you should know about.

The Art of Playing Jazz Guitar - A True Preparation Primer Part 1
By: John Belthoff | 26/03/2006 | Art & Entertainment
I'm not going to kid you; playing Jazz Guitar is extremely difficult at best and almost downright impossible at worst. However there are things you can do to improve your improvisation skills and feeling...

Article Categories





Give Feedback

Sign up for our email newsletter

Receive updates, enter your email below