using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Text;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace CustomControls
{
   [DefaultProperty("Text")]
   [ToolboxData("<{0}:CountedButton runat=server></{0}:CountedButton>")]
   public class CountedButton : System.Web.UI.WebControls.Button
   {

      // Konstruktor inicjalizuje warto ViewState.
      public CountedButton()
      {
         this.Text = "Kliknij przycisk";
         ViewState["Count"] = 0;
      }

      // Count jako waciwo obsugiwana przez ViewState.
      public int Count
      {
         get
         {
            return (int)ViewState["Count"];
         }

         set
         {
            ViewState["Count"] = value;
         }
      }

      // Uniewaniamy OnClick, zwikszajc warto waciwoci Count,
      // uaktualniamy tekst przycisku, a nastpnie wywoujemy podstawow metod.
      protected override void OnClick(EventArgs e)
      {
         ViewState["Count"] = ((int)ViewState["Count"]) + 1;
         this.Text = ViewState["Count"] + " klikni";
         base.OnClick(e);
      }

   }
}
