title: How do I increment a step value to be processed when the page loads in ASP.NET?
body: <p>How do I increment a step value to be processed when the page loads? For example, in the code below the viewstate variable is not incremented until after Page_Load, due to the ASP.NET page lifecycle.</p>
  
  <pre><code>protected void Page_Load(object sender, EventArgs e)
  {
      switch ((int)ViewState["step"])
      {
          //do something different for each step
      }
  }
  
  protected void btnIncrementStep_Click(object sender, EventArgs e)
  {
      //when the button is clicked, this does not fire 
      //until after page_load finishes
      ViewState["step"] = (int)ViewState["step"] + 1;
  }
  </code></pre>