Question

I have asp GridView that is present in multiple pages. In gridview there are checkboxes, hyperlink,textboxes and edit button to edit text in Gridview. In some pages there is functionality that checkboxes,textboxes data is transmitted to server for delete or edit in DB. I was thinking of optimizing pages. So is it a good idea to use ViewState as false for GridView?

Was it helpful?

Solution

You shouldn't really optimize unless you are experiencing a problem. Are the pages measurably slow? Are you sure that it's the GridView's view state data that's causing the slowness? Use some kind of profiling tool, or measureable benchmarks, to determine if there's a slowdown, and where that slowdown is.

In addition to all that, turning off the view state will require additional programming on your part. Feel free to try it, and see what happens. I'll mention a few "gotchas" that you'll probably run into.

I assume right now you are binding data to your GridView on Page_Load inside a if(!Page.IsPostBack) block. Once you do that, you don't have to bind the data again (during normal PostBacks) because the view state is maintaining the state of your control.

If you turn the view state off for that GridView, you will have to bind the data back to it on every post back. You will also have to manually maintain other aspects of the state of the Grid (whether its in edit mode, for instance).

This is just one of the many tradeoffs you have to consider when making decisions like that (is the extra programming time worth the potential gain you get from this optimization?).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top