views:

22

answers:

2

Is it possible to do data caching in client-side in asp.net and c#.net? iam planning to cache a dataset. if so please provide a sample?

A: 

For asp.net & c#.net web application its best to cache these kind of things in server side datacache.

The only form of client side cache that I can think of for this is to put the dataset in a session object

Ivo
A: 

The only real option you have to store large amounts of data client side is by using the ViewState. It will only exist on the page you add it to though. So if you are jumping around from page to page it won't really work. In that case you really should be using Session or Application Cache depending on your scenario.

So if you are doing something where you are always on the same page and just doing many PostBacks for things like paging or sorting then ViewState will work fine but do realize you will be passing large amounts of data back and forth to the server each time a PostBack is made.

Eg:

// Set it
ViewState["YourData"] = yourDataSet;

// Get it
DataSet ds = ViewState["YourData"] as DataSet;

Session and the Application Cache are accessed the same way. Just replace ViewState with the word Session or Cache.

More information regarding the 3 methods can be found on MSDN:

  1. ViewState
  2. Session
  3. Application Cache

You might want to check out the following links as well:

http://stackoverflow.com/questions/428634/cache-v-s-session

http://stackoverflow.com/questions/1899591/session-state-v-viewstate

http://www.codeproject.com/KB/aspnet/PTCacheSessionViewState.aspx

Kelsey