O'Reilly logo

C# Primer: A Practical Approach by Stanley B. Lippman

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required