namespace StateManagement

{

    public partial class SessionExample1 : System.Web.UI.Page

    {

        protected void Page_Load(object sender, EventArgs e)

        {

 

        }

 

        protected void btnVote_Click(object sender, EventArgs e)

        {

            int count = 0;

 

            // Check to see if there is a value stored in the Session before using it.

            // The Session variable (key-value) doesn't exist until the

     // user's session clicks the button for the first time.

            if (Session["VoteCount"] != null)

                count = (int)Session["VoteCount"];

 

            count = count + 1;

            Session["VoteCount"] = count;

            lblDisplay.Text = "You voted " + count + " times.";

        }

 

        protected void btnViewResults_Click(object sender, EventArgs e)

        {

            Session["Name"] = txtName.Text;

            Response.Redirect("SessionExample1_Results.aspx");

        }

    }

}