7.9. Managing State: Class Members

How do we store the mouse click count? My first thought was to introduce instance members within the WebForm1 class that represents the page:

public class WebForm1 : System.Web.UI.Page
{
   // generated by Web Forms designer ...
   protected System.Web.UI.WebControls.TextBox TextBox1;
   protected System.Web.UI.WebControls.Label Label1;
   protected System.Web.UI.WebControls.Label Label2;
   protected System.Web.UI.WebControls.ListBox ListBox1;
   protected System.Web.UI.WebControls.Label Label3;
   protected System.Web.UI.WebControls.ImageButton ImageButton1;

   // OK: my guys ...
   protected int AnnaCount;
   protected int PoohCount;
   protected int MissCount;

Unfortunately, this fails miserably. The page is reloaded with each post back, ...

Get C# Primer: A Practical Approach now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.