How: Multiple controls raise the same event.
-
Hello all, I writing several user controls for a ASP.NET in C#. I want to get all the controls to be able to raise the same event, how can I do that? More info: The problem I’m facing is: I defined the delegate under the name space so it can be seen from any class, but the events are defined within the class scope. Now the problem is when the user control tries to raise the event, I found that the event is null (it hasn’t been constructed). Any help is highly appreciated Thanks
-
Hello all, I writing several user controls for a ASP.NET in C#. I want to get all the controls to be able to raise the same event, how can I do that? More info: The problem I’m facing is: I defined the delegate under the name space so it can be seen from any class, but the events are defined within the class scope. Now the problem is when the user control tries to raise the event, I found that the event is null (it hasn’t been constructed). Any help is highly appreciated Thanks
An event will be null until you attach a method to it from the page with MyControl.MyEvent += new MyEventHandler(MyMethod). Thus when you call an event, you should always check that it isn't null first. Is that your problem or am I missing the point? Paul
-
An event will be null until you attach a method to it from the page with MyControl.MyEvent += new MyEventHandler(MyMethod). Thus when you call an event, you should always check that it isn't null first. Is that your problem or am I missing the point? Paul
Yup, This helped me. Thanks Paul!