Recent Articles

BlogEngine.NET: Events In The File & Image Handlers
In BlogEngine.NET, all files and images that are inserted on a post will be served using an HttpHandler. Actually, they are served by FileHandler and ImageHandler respectively. They are almost identically and...

New Blog Engine Written In ASP.NET 1.1
For more than a year, I've been blogging on the excellent dasBlog engine and it has been good. I really like the fact that it runs on XML instead of a database. However, it is written in ASP.NET 1.1 and is quite...

ASP.NET: Count Clicks On External Links
On a small test website I'm building in my spare time, I wanted a way to count the number of clicks to the outgoing links from that site. Imaging hosting banners or other affiliate links where you get paid per click...

Creating Reusable User Controls In ASP.NET
In almost every web project of any size, you would probably use a lot of user controls to separate the content and UI logic. Many of the user controls are used only at one place in the solution while others are used by various pages and other user controls. The ones...

ASP.NET: Is It Too Easy?
Some time ago, I wrote a post called "Is ASP.NET too difficult?" and I strongly believe that it is. Yet at the same time it cause problems by making it too easy to do relative advanced programming. It doesn't seem...



Recent WebProNews Articles

Google And Yahoo To Take 90% Of Paid Search
U.S. Internet users did 75. 8 percent of their January 2007 searches on Google or Yahoo, according to comScore media, and Nielsen//NetRatings found the combined total to be 76.4 percent. "In fact, over 90%...

Google By Numbers; Profits Flatten Out
Revenue and profits rose for Google in their first quarter, earning net income of $1 billion on $3.66 billion in revenue. That net income is a little less than that of fourth quarter 2006, which reached $1.03 billion.

Google Slips Webmasters More Anchor Phrases
FThe Webmaster Central tools from Google received a welcomed update last month, to display anchor phrases leading to a site. Google has expanded upon that feature. Webmasters should be pleased with the...

Schmidt Defends DoubleClick Buy, Net Neutrality
At the Web 2.0 Expo in San Francisco, Google CEO Eric Schmidt spoke with Federated Media's John Battelle to discuss Google's purchase of DoubleClick, Network Neutrality, and the company's seemingly aggressive...

Yahoo Checks Out PayPal For Payments
Yahoo and eBay announced the Yahoo PayPal Checkout Program, which users of Yahoo Search will encounter as little blue shopping cart icons in the search results. Merchants who participate in the Program will be able...


04.20.07


ASP.NET - Asynchronous GridView In 5 Steps

By Mads Kristensen

A web page with a data bound GridView control can take a long time to load.

The page is not rendered until all the controls are, and the GridView cannot render before data has been retrieved from the database. So, let's load the GridView asynchronous and make the page load faster and the perceived speed greater.

This little trick is actually very simple and it involves the built-in client callback feature of ASP.NET. Even though I'm not a big fan of that particular feature, it can be quite handy from time to time. The best part of this is that you don't have to change much to your existing code.

Web page

On the webpage that hosts the GridView control, you have to make 2 small changes.

Step 1. Encapsulate the GridView

The GridView control has to be encapsulated by an HTML control with an id attribute, so that it can be referenced by JavaScript. That is because the GridView does not render when no data is bound to it.



Step 2. Add a JavaScript

Then a JavaScript is needed to load the rendered and data bound GridView to the HTML control we added in step 1. Place the JavaScript below the GridView's surrounding div tag.

Low Rate eCommerce & Retail Plans



Code-behind

In the code-behind file there are three small steps to perform.

Step 3. Implement ICallbackEventHandler

We need to implement the interface to turn on the client callback feature.



Step 4. Bind the call back reference

The literal control placed in the JavaScript function in step 2 has to contain the client callback reference. Add the following to the Page_Load.



Step 5. Bind the grid and return the rendered HTML

To finish the asynchronous loading we have to implement the two methods that are defined by the ICallbackEventHandler interface we implemented in step 3. One of the methods binds a DataTable to the GridView and renders the control. The second returns the rendered HTML to the JavaScript method we defined in step 2.



You can use your present data binding method to bind the GridView. The important part is that the GridView is data bound before the RaiseCallbackEvent method renders the control.

The same technique can be used for all the data control such as the Repeater, FormView and DataList.

Download

asyncgridview.zip (1,21 KB)

Comments


About the Author:
Mads Kristensen currently works as a Senior Developer at Traceworks located in Copenhagen, Denmark. Mads graduated from Copenhagen Technical Academy with a multimedia degree in 2003, but has been a professional developer since 2000. His main focus is on ASP.NET but is responsible for Winforms, Windows- and web services in his daily work as well. A true .NET developer with great passion for the simple solution.

http://www.madskristensen.dk/

About WebProASP
WebProASP is a collection of up to date tutorials and insightful articles designed to help ASP users of any skill level implement successful ASP systems and practices. ASP Strategies and Tactics for Business

WebProASP is brought to you by:

SecurityConfig.com NetworkingFiles.com
NetworkNewz.com WebProASP.com
DatabaseProNews.com SQlProNews.com
ITcertificationNews.com SysAdminNews.com
WebProASP.com WirelessProNews.com
CProgrammingTrends.com ITManagementNews.com




-- WebProAsp is an iEntry, Inc. publication --
iEntry, Inc. 2549 Richmond Rd. Lexington KY, 40509
2007 iEntry, Inc.  All Rights Reserved  Privacy Policy  Legal

archives | advertising info | news headlines | free newsletters | comments/feedback | submit article



ASP Strategies and Tactics for Business WebProASP News Archives About Us Feedback WebProASP Home Page About Article Archive News Downloads WebProWorld Forums Jayde iEntry Advertise Contact