Setting Class-Level Variable to Use Between Event Handlers
<p>I'm having a hard time understanding why the following code doesn't work. I'm sure it's something remedial that I'm missing or not understanding. I currently have a page that asks for user input. If, based on the input and logged in user, I find data from this page already in the database, I need to update the existing records rather than creating new ones, so I set a class-level bool to true. The problem is, when MyNextButton is clicked, PreviouslySubmitted is still false. So, I'm not sure how to make the value of this variable persist. Any advice is appreciated, thanks.</p>

<pre><code>public partial class MyForm : System.Web.UI.Page
{
    private bool PreviouslySubmitted;

    protected void Page_Load(object sender, EventArgs e)
    {
        MyButton.Click +=
            (o, i) =&gt;
            {
                q = from a in db.TableA
                    where (a.SomeField == SomeValue)
                    select a;

                if(q.Any())
                {
                    PreviouslySubmitted = true;
                    //populate the form's fields with values from database for user to revise
                }
            }

        MyNextButton.Click +=
            (o, i) =&gt;
            {
                //the value of PreviouslySubmitted is false at this point, 
                //even if I made sure it was set to true the previous postback

                if(PreviouslySubmitted)
                {
                    //update database
                }
                else
                {
                    //insert into database
            }
    }
</code></pre>
