1

I have a gridview on my page that gets bound to user search results. There can be many pages upto say 1000. Each page shows 50 records. I have the built in paging turned on for the grid. I want to disable the viewstate on the grid but then I have to bind the results on every page load. (bind twice on paging). The search takes a few seconds and I would not want to store the results in the session. So, how do I achieve turning off the viewstate for the grid or is it okay to have it enabled?

This must be a very common scenario. I hope there is a standard way of doing this.

coder net
  • 3,447
  • 5
  • 31
  • 40
  • Why do you want to disable ViewState, are the 50 records too much for the page? Also consider not only to use paging of the Grid but also paging of the datasource itself. Example with SQL-Server as DBMS: http://stackoverflow.com/questions/548475/efficient-way-to-implement-paging – Tim Schmelter Jun 13 '11 at 18:14
  • The performance of this page is extremely important. The query does a look up in a table with 1.4 million records. I had it initially in a CTE but that adds around 2 seconds more than a regular select. As for take and skip, i have to also display the total count for the records next to the paging. This kind of throws away the benefits of take /skip as i have to calculate the total # of results. The custom paging is doable. I just did not have enough time to work on it. But that still does not solve the issue of viewstate. I am just trying to optimize the page removing any unnecessary overhead. – coder net Jun 13 '11 at 18:21

1 Answers1

1

Depending on how you bind the grid view you should implement server side paging so that your only bringing back the data from the server you need to display for one page.

What data access are you using i.e. are you using linq to sql?

Heres an article on how to do it with ObjectDataSource Custom paging and sorting

Avoid where ever possible putting large amounts of info into view state as it will bloat your page and effect performance.

Richard Forrest
  • 3,567
  • 2
  • 23
  • 32
  • how does this help with the viewstate. Even if I do custom paging, it is going to take a few seconds to get the results back due to the nature of the complexity of the query and size of the table. I'm just trying to avoid unnecessary overhead to the page. But it is a nice article that i'll look into now. – coder net Jun 13 '11 at 18:24
  • It will help your performance as you will only be pulling 50 record from the server not 50000. This much smaller set could then be added to viewstate if needed. – Richard Forrest Jun 13 '11 at 18:29
  • I believe if the grid binds to 50k records but displays only 50 at a time, the viewstate will have data only for 50 not the whole set. I have around 17 columns displaying max 8 chars each. so, it adds up. – coder net Jun 13 '11 at 19:00
  • i'll accept your answer since it does improve performance in my case. I suppose viewstate is not as big of an issue as I think it is although it adds around 5kb data. – coder net Jun 13 '11 at 19:17