.NET - Create Custom Event for Class/UserControl
To create a custom event for your class or usercontrol:
1. Define your own delegate either within the class or in a shared library. (or use an existing .NET EventHandler)
public delegate void DeleteEventHandler(object sender, EventArgs e);
2. Define an event within the class/usercontrol. An important thing here is the 'event' keyword.
public event DeleteEventHandler Deleted;
3. Fire the event anytime within the class.
protected void DeleteClick(object o, ImageClickEventArgs e)
if (Deleted != null)
4. Any other class can attach to the event in the normal way. Make sure if you attach that you are handling detach where needed.
Created By: amos 1/26/2011 4:34:50 PM
Updated: 9/3/2013 11:26:06 AM