title: Best Practice for storing data in an ASP.NET web page
body: <p>I have a multi-user set of ASP.NET web pages. The pages use AJAX update panels so I can avoid updating the screen on every postback. 
  The lifecycle of each page is as follows:<br>
  1. During Page_Load, get relevant data for user from a web service.<br>
  2. Store the data (quite large), and a service reference in a static dataset.<br>
  3. allow various edits to parts of the data via the screen controls (grids, text boxes)<br>
  4. validate data captured via form<br>
  5. send updated data back to service  </p>
  
  <p>I am doing this using static variables in the Page class itself as follows:</p>
  
  <pre><code>public partial class MyPage : System.Web.UI.Page
  {
      static xxxx.DataCaptureServiceClient  m_Service; //reference to web service
      static string m_PersonID = string.Empty;  //current person_id page is viewing
      static ServResponse m_ServiceResult = null;        // reference to our data to edit ( ServResponse is a large data contract)   
      static string m_SortExpression = "Reference"; //default sort expression for grid
  
      const int PERSONID_COLUMN = 0;        //column index in grid for the personID column
      const int STATUS_COLUMN = 4;          //column index in grid for the application status
  
      protected void Page_Load(object sender, EventArgs e)
      {
          try
          {
              if (!Page.IsPostBack)
              {
                  // Get new service instance.
                  m_Service = new xxxx.DataCaptureServiceClient();
  
                  ShowDataOnPage(); //get data in m_ServiceResult and bind to a grid on screen
              }
          }
          catch (Exception ex)
          {
              Response.Redirect("ErrorPage.aspx", false);
          }
      }
  
      protected void butNext_Click(object sender, EventArgs e)
      {
          try
          {
              Page.Validate();
  
              if (Page.IsValid)
              {
                  // Use m_ServiceResult and m_Service to send a packaged submission to the service.
                  SendDatatoService();
                  Response.Redirect("TheNextPage.aspx", false);
  
              }
          }
          catch (Exception ex)
          {
             Response.Redirect("ErrorPage.aspx", false);
          }
  }
  
  //Other methods which allow edits to m_ServiceResult
  </code></pre>
  
  <p>I am wondering if:</p>
  
  <p>A) This is a good way to implement or are there better practices?<br>
  B) Should I clear down memory by setting all statics to NULL when I redirect to another page?<br>
  C) If I clear down the statics do I risk another user losing data?    </p>
  
  <h2>UPDATE</h2>
  
  <p>I have rewritten removing the statics, keeping the const values and passing data I need around as parameters. Where I need to keep data for updates I have kept the minimal amount I need in session[] variables.</p>