<%@ Page language="c#" %>
<%@ Register TagPrefix="uc1" TagName="Control" Src="Control.ascx" %>
File: Control.ascx
<%@ Control Language="c#" AutoEventWireup="false" Codebehind="Control.ascx.cs" Inherits="Control.Control" TargetSchema="http://schemas.microsoft.com/intellisense/ie5" %>
File: Control.ascx.cs
namespace Control
{
using System;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
public abstract class Control : 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((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);
}
}
override protected void OnInit(EventArgs e)
{
InitializeComponent();
base.OnInit(e);
}
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);
}
}
}