Visual Studio sharepoint webparts onload and onload to save state before rerendering
<p>I'm working on an application for Sharepoint 2010, using visual studio 2010, and programming in C#.  </p>

<p>My application has a web part that displays some data that is pulled from a Sharepoint list and/or database.  My application displays the pulled data in web.UI textboxes.  So far, everything is fine.  I also have another web part, on the same page as the application web part I developed, that is a content editor web part, and I use that content editor to reload the page every two minutes with javascript.  </p>

<p>Here's the issue: my web part that pulls the data from the sharepoint lists and/ or database needs to display only the most recent and up to date data.  The "display up to date data" works fine if the information is in the database or the list before the auto-refresh (which happens every two minutes, and is written in javascript in a content editor web part) kicks in.  Any data that is input into the textboxes before the auto-refresh gets deleted.  I know that the auto-refresh invokes several methods when the page is refreshed.  I therefore have tried overriding the Onload and OnUnLoad methods of the web part.  I simply inserted into the onload and onunload method a call to a method that saves my data, like this:</p>

<pre><code>    protected override void OnUnload(EventArgs e)
    {

        SaveEntireTrainBuilder(true);
        snoutput.Text += "Saved On Load" + " has unload snoutput";
        base.OnUnload(e);
    }



    protected override void OnLoad(EventArgs e)
    {
        if (!Controls.Contains(snoutput))
        {
            CreateChildControls();
            SaveEntireTrainBuilder(true);
            snoutput.Text += "Saved On Load" + " no snoutput";
        }
        else
        {
            SaveEntireTrainBuilder(true);
            snoutput.Text += "Saved On Load" + " has snoutput";
        }
    }
</code></pre>

<p>However, this way seems to erase whatever changes I enter into the application manually between refreshes.  I'm thinking that this is because Onload calls createchildcontrols to recreate all the child controls in the program, and that my save step should be in the OnUnload method (ie onunload -> createchildcontrols to recreate the controls on the webpart -> onload, or something like that).  Is there a way to get this effect?  To essentially tell the program that, right before everything is wiped off with the refresh, to save everything, then refresh, and reload the program from the data that was saved right before the refresh (so that the refresh will always have the most recent data, including stuff that was typed in between refreshes and wasn't explitily saved, the program needs to auto-save). </p>
