Fire Event From User Control

D

Da Rabit

I need to fire an event from a user control and catch it in the parent page.
I cant seem to find any help in the MSDN etc.
Any code examples / refrences will help greatly .
Thanks in advance
Elrond Bishop
 
R

Robert Koritnik

You will have to make an event in your User control and on the page you will
have to handle it. Check MSDN for event tutorial.

For each event in your control (user of custom) you have to write this code
to make it the proper way:

protected virtual void OnSpecialClick(SpecialEventArgs e)
{
SpecialEventHandler specialEvent =
(SpecialEventHandler)Events[SpecialEvent];
if (specialEvent != null) specialEvent(this, e);
}
private static readonly object SpecialEvent = new object();
public event SpecialEventHandler SpecialClick
{
add { Events.AddHandler(SpecialEvent, value); }
remove { Events.RemoveHandler(SpecialEvent, value); }
}
 

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

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top