subash subash -4 years ago 105
ASP.NET (C#) Question

Data caching client side in asp.net?

Is it possible to do data caching in client-side in asp.net using c#?

I am planning to cache a

Dataset
. If so can you please provide a sample?

Answer Source

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:

Advantages of Cache vs Session

Session State v ViewState

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download