How to Save datasource to be accessed after PostBack

Posted on 2011-05-07
Medium Priority
Last Modified: 2012-05-11
I have a datalist in which I may display upto 5000 or more records. Since the viewsource becomes huge I have disabled viewsource on this page. I need to page the datalist. So how can I store and retrieve the data after the user clicks on Next Page? Should I store the data in Session? If so can I store the datatable in session? Thanks
Question by:TrialUser

Expert Comment

ID: 35713509
Yes, you can save DataTable in Session Just Try

DataTable dt = new DataTable(); //Or What Ever Datatable you want

Session["tblData"] = dt;

// To retrieve it from session
DataTable dt = (DataTable)Session["tblData"];

LVL 75

Accepted Solution

käµfm³d   👽 earned 668 total points
ID: 35713523
Storing an entire DataTable in the Session objects seems like a bad idea. Is this a high-traffic site? Each person actively using your application is going consume memory (assuming you are using InProc sessions) for 5000 records. Food for thought  = )

Author Comment

ID: 35713699
I am storing session in database and not in memory. Having said that is storing in session ok?
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


Author Comment

ID: 35713704
Currently there may be 100 users in a day. But the plan is too increase and support. I want to write a website that will be scalable and not have to worry about this in the future. Please suggest. Thanks
LVL 13

Assisted Solution

iHadi earned 664 total points
ID: 35713740
I suggest you use Caching techniques. The caching techniques helps you speed and improve the performance of you app, and also protects the server from memory overload.

There are a lot of types of caching in asp.net. The output cache and even a kernel level cache which is so fast and reduces a lot of CPU, the cache object in your application context, ...

Some features of .net caching are:
- There is a dependency for cached items that states when the cached items should be refereshed, this also protects the memory from unused cached items.
- A very carefully and professional cache engine built and timely tested, for solving problems like yours and others, and many experts have put their minds into it.
- The cached items can be shared globally in your application, so more than one user can benefit from it.
- A smart engine that can clear cache according to the way it is used and it's importance if the memory is overloaded or near overloading.

and other benefits which you can look them up online. There is a lot of performance problems that caching is part or all the solution to them.

Author Comment

ID: 35713815
IS there any disadvantage of caching? Like memory?
LVL 13

Expert Comment

ID: 35713826
Of course, caching uses memory, so overusing it can affect memory. If you describe your scenario more, I can help you with the design better.

Author Comment

ID: 35715875
I am developing an eCommerce website. ASP.NET/VB.NET 2010/SQL Server 2008.

The users can search for products. The search in some cases may return about 5000 records or more. The viewstate increases > 4MB in that case. One option for me would be to limit the records resultset to <1000. If I dont want to do that then I want to know what would be the best way to handle the records that are returned from the db.

Currently I have disabled the Viewsource in the page so the page does not crash after >5000 records.
Then how do I do paging sorting etc. Should I save the results in Session/Cache or do SQL paging (return only records that are displyed) and fetch the records everytime from the db.

Please help. Thanks
LVL 83

Assisted Solution

CodeCruiser earned 668 total points
ID: 35715984
I think you should do the page on the data base server. Let's say a user opens the page which has the datalist. He sees the first page and then opens another page or closes the page. You are loading 4000 records and the user is probably only looking at 10! That's a huge waste of processing, bandwidth and memory. Implement the paging on the server in a stored procedure.







Featured Post


Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
Loops Section Overview
Suggested Courses

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question