Reflection-Event Handling...

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

Guest

I am dynamically loading controls on a page and want to wire up a generic
event for all to use. I need to pass a custom EventArgs to the event called
CommunicationEventArgs. How do I do this? I am not sure what to put in for
the question marks below. If I dont put anything it complains about missing
arguments. The signature for the delegate in the User Controls is
public delegate void CommunicationEventHandler(object sender,
CommunicationEventArgs ce);

What do I need to put in for the questions marks below to get this to work??

Control mControl = (Control)LoadControl("mycontrol.dll");

mControl.GetType().GetEvent("SendMessage").AddEventHandler(mControl,new
EventHandler(this.TestingEvent(?,?))));

public void TestingEvent(object sender, CommunicationEventArgs e)
{
Response.Write (e.Message);
}

Thanks in advance!!!
 
happyone said:
I am dynamically loading controls on a page and want to wire up a generic
event for all to use. I need to pass a custom EventArgs to the event called
CommunicationEventArgs. How do I do this? I am not sure what to put in for
the question marks below. If I dont put anything it complains about missing
arguments. The signature for the delegate in the User Controls is
public delegate void CommunicationEventHandler(object sender,
CommunicationEventArgs ce);

What do I need to put in for the questions marks below to get this to work??

You don't - you don't include the brackets, and you create the right
type of delegate:

new CommunicationEventHandler(TestingEvent)
 
Back
Top