Web
ASP.NET AJAX
Often we find it easy to create a class with a static event to keep the controls in our web application loosely coupled. The easiest way to make a number of controls interact without “knowing” about each other is to have a static event distributor class. public class EventDistributor
{
public static event EventHandler SomethingHappened;
public static void RaiseSomethingHappened(object sender, EventArgs e)
{
if (SomethingHappened != null)
{
SomethingHappened(sender, e);
}
}
}
Some of the controls raise the events of the distributor… protected void Button1_Click(object sender, EventArgs e)
{
…
EventDistributor.RaiseSomethingHappened(sender, e);
…
}
…and others subscribe to them protected void Page_Load(object sender, EventArgs e)
{
...