Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GridView loses data during postback

I have an aspx.Page containing a gridview. The gridview is bound in code behind to a datasource only when no postback takes place and has enableviewstate = true (The page too). During a postback, the data bound to the gridview are lost. What could be the reason. Please ask if code is needed.

like image 240
AGuyCalledGerald Avatar asked Dec 22 '10 13:12

AGuyCalledGerald


2 Answers

Solved it, problem was I made a Page.Databind() in the Page_Load event of the masterpage of the page with the gridview, so it bound the gridview during each postback without data. Thanks for all efforts.

like image 164
AGuyCalledGerald Avatar answered Sep 24 '22 16:09

AGuyCalledGerald


This is by design. This data is not stored anywhere natively from page load to page load. You will need to perform one of the following 3 tasks:

  1. Store the data in ViewState (not necessarily recommended if the data is large)
  2. Store the data in a Session object (same story, large data equals bad memory usage)
  3. Make a return trip to rebind the data each time the page loads (breaks down if there is too much activity on the database or if the query is slow)

My preference is to make return trips to the database when I need to and keep my SQL tuned for performance. Heavy page loads are annoying, and too much session memory can cause slowing on the server. I believe you can also store this data in cache, but I've never attempted it so I don't know what the limitations or capabilities there are.

like image 39
Joel Etherton Avatar answered Sep 21 '22 16:09

Joel Etherton