Follow me on Twitter at Twitter.com/wbm
FYI, I'm blogging most of my stuff over at More Wally now.
You might want to add my rss feed to your reader at:http://morewally.com/cs/blogs/wallym/rss.aspx
ASP.NET 4.0 AJAX - Caching Data on the client - Wallace B. McClure

Wallace B. McClure

All About Wally McClure - The musings of Wallym on Web, HTML5, Mobile, Xamarin.iOS, Xamarin.Android, and Windows Azure.

News

Visual Studio Magazine Column Personal Blog

.NET

Book Authors

Business

Family

Friends

Georgia Tech Bloggers

Personal

Archives

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