Viewing source for Recipe0206cs.ascx.cs

namespace AspNetCookbook
{
	using System;
	using System.Data;
	using System.Drawing;
	using System.Web;
	using System.Web.UI.WebControls;
	using System.Web.UI.HtmlControls;

	/// <summary>

	///		Summary description for Count.

	/// </summary>

	public abstract class Recipe0206cs : System.Web.UI.UserControl
	{
		protected static readonly object EventMultipleReached = new Object();
		protected System.Web.UI.WebControls.Label OutputLabel;
		private int multiple = 10;
		public int Multiple 
		{
			get 
			{
				return multiple;
			}
			set
			{
				multiple = value;
			}
		}
		private void Page_Load(object sender, System.EventArgs e)
		{
			if(Application["count"] == null)
				Application["count"] = 0;
			Application.Lock();
			Application["count"] = (int)Application["count"] + 1;
			Application.UnLock();

			// if number of hits is a multiple of Multiple, raise event

			if((int)Application["count"] % Multiple == 0)
				OnMultipleReached(EventArgs.Empty);

			OutputLabel.Text = Application["count"].ToString();
		}

		public event EventHandler MultipleReached 
		{
			add 
			{
				Events.AddHandler(EventMultipleReached, value);
			}
			remove
			{
				Events.RemoveHandler(EventMultipleReached, value);
			}
		}

		public virtual void OnMultipleReached(EventArgs e)
		{
			EventHandler MultipleReachedHandler = (EventHandler)Events[EventMultipleReached];
			if (MultipleReachedHandler != null)
			{
				MultipleReachedHandler(this, e);
			}
		}

		#region Web Form Designer generated code
		override protected void OnInit(EventArgs e)
		{
			//

			// CODEGEN: This call is required by the ASP.NET Web Form Designer.

			//

			InitializeComponent();
			base.OnInit(e);
		}
		
		///		Required method for Designer support - do not modify

		///		the contents of this method with the code editor.

		/// </summary>

		private void InitializeComponent()
		{
			this.Load += new System.EventHandler(this.Page_Load);

		}
		#endregion
	}
}