Link to home
Start Free TrialLog in
Avatar of bobstery
bobstery

asked on

Web Part post back problem

I have a web part that I am trying to use within Sharepoint 2007. The web part has two drop down menus that are used to execute a SQL stored procedure.  When the stored procedure is executed it creates a table with the rows being dynamically determined by the stored procedure results.  I also have a button within the web part that adds a new row to the table, this causes a post back and a new row is added.  The problem comes when the post back occurs as the code to dynamically create the table is called again and any information the user has changed on the page reverts back to the data from the stored procedure.

Is it possible to have data in a table edited and then keep that same information when a post back occurs?
SOLUTION
Avatar of neilrichards
neilrichards

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Jamie McAllister
Sounds like you need to store the data in Viewstate and not make the call to DB on every page load.

Look into overriding the SaveViewState and LoadViewState methods to handle your data between postbacks.
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of bobstery
bobstery

ASKER

So if I save the contents of the table into an array (in the SaveViewState method) I can load the data back into the web part in the LoadViewState method?
You can put a one dimensional array in viewstate. Any more dimensions than that are tricky.

If you can't use the array for this reason you could serialise it to XML and store that away in a string or some such.