Custom Event Handling within UserControl

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am trying to kick off an custom event in a usercontrol that the webpage
will listen and preform some actions if the event is fired from within my
usercontrol
 
First you need to create a delegate. Do this outside the class:

public delegate void MyCustomEventHandler(object sender, MyCustomEventArgs e);

The above is an example of a delegate that you can define.

In side the class you then do the following:

public class MyClass
{
public event MyCustomEventHandler MyEvent;
.....
}

To fire the event you can do this:

if (MyEvent != null)
MyEvent(sender, args);
 
Back
Top