ASP.NET 4.0 AJAX - Caching Data on the client - More Wally - Wallace B. McClure
in

MoreWally.com

Giving people what they want, More Wally. This is the technical and personal blog site of
Wallace B. (Wally) McClure.

This Blog

Syndication

News

Please goy buy 3-4 copies of my book on MonoTouch titled "Professional iPhone Programming with MonoTouch for .NET/C# Developers." They make great gifts all year round. Plus, I get about $.20 when you buy a copy.

Technical Sites

More Wally - Wallace B. McClure

This blog will have all kinds of posts about Wally McClure. In it, there will be tons of .NET and computer programming posts as well as Wally's views on life in general. As you might guess, this site and blog help you get More Wally in your life. What more could anyone want? iPhone, Android, MonoTouch, MonoDroid, Mobile, HTML5, .NET, ADO.NET, ASP.NET, AJAX, Atlas, Microsoft AJAX Library, ASP.NET AJAX, and Windows Azure............follow me on twitter at Wally

ASP.NET 4.0 AJAX - Caching Data on the client

One of the interesting new objects in ASP.NET 4.0 AJAX is the DataView.  its a client side object which is associated with a display tag of some type.  In my examples, I've been using a table.  I assume it could be anything.  One of the features of the DataView is the ability to call an event each time a record is bound to the DataView.  This is similar in concept to the server side asp.net grids which have the OnRowDataBound events (or similarly named).  One of the common scenarios that I see is to have a drop down list box inside of a record.  This could represent typically anything.  As I was working through the DataView, I thought about some type of efficient way to cache the data.  In my scenario, the data is constant across the rows, so caching it is fairly easy.  Anyway, here goes:

  1. I call the method to get my data first before doing anything else in my page load client side event:
            TwitterService.GetFriends(userName, StoreFriendsCallBack);
            TwitterService.GetUserTimeLine(userName, TwitterServiceCallBack, TwitterServiceFailure);
  2. In side of my StoreFriendsCallBack method, all I do is store my data to a global js variable I call dd.
        function StoreFriendsCallBack(result) {
            dd = result;
        }
  3. Finally, I test to see if my dd (dropdown) object has any data or not.  If it has data, I use it, if not, then I go ahead and call back to the server to get my data.
            if (dd == null) {
                TwitterService.GetFriends("More_Wally", FriendsCallBack, null, userCtx);
            }
            else {
                DisplaySelect(dd, userCtx);
            }

Comments

No Comments
2006 - Wallace B. McClure
Powered by Community Server (Non-Commercial Edition), by Telligent Systems