using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using FourLayer.BusinessEntity;

public partial class UsingViewState : System.Web.UI.Page
{
   protected void Page_Load(object sender, EventArgs e)
   {
      if (!IsPostBack)
      {         
         panCount.Visible = false;

         // inicjalizacja zmiennych stanu widoku
         ViewState["PostbackCount"] = 0;

         Book book = new Book();
         book.Isbn = "0000000001";
         book.Title = "Tysiąc sposobów na użycie stanu widoku";
         ViewState["Książka"] = book;

         ViewState["temp"] = 16.5;
      }
   }
   protected void btnRequest_Click(object sender, EventArgs e)
   {
      int count = (int)ViewState["PostbackCount"];
      count++;

      ViewState["PostbackCount"] = count;
   }
   protected void btnShow_Click(object sender, EventArgs e)
   {
      panCount.Visible = true;
      int count = (int)ViewState["PostbackCount"];
      labCount.Text = count.ToString();
      Book book = (Book)ViewState["Książka"];
      labBook.Text = book.ToString();

      double temp = (double)ViewState["temp"];
      labBook.Text += temp.ToString();
   }
}
