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);
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top