Although this questions pertains to a web project, it is c# specific.....
There is an event I need to subscribe to on a user control I'm working with. The user control has several of its own controls, one of which is a third-party treeview. I need to subscribe to the treeview's NodeClick event. The problem is that I need to use a base class to subscribe to the event instead of the page/pages that the user control is on. So basically the framework looks something like this....
User Control - Holds treeview
Web Page - Holds user control (Inherits Base Class)
Base Class - The Base Class for all web pages in the project (Inherits System.Web.UI.Page).
To further complicate things the base class is in a separate assembly and cannot reference the assembly that holds the user control and pages (this would cause circular dependency). I've tried to use Reflection and also tried using an Interface... Haven't had any luck with either... Currently the problem I am having is in the Base Class. I am trying to use System.Reflection.MethodInfo so I can create a delegate, but it requires the method to be static and making the method static makes it so MethodInfo can't find the method at all! This is driving me crazy... I've been working on it for a few days now... Any help would be greatly appreciated.
Currently, there isn't a lot of code since I recently wiped it out and started over... but here is the line that I am having issues with....
mi is coming back null. MyMethod is static. Also, when I make the method public instead of static the GetMethod command works but I need it to be static to create the delegate.
Kevin Davie
Consultant
Sogeti USA
There is an event I need to subscribe to on a user control I'm working with. The user control has several of its own controls, one of which is a third-party treeview. I need to subscribe to the treeview's NodeClick event. The problem is that I need to use a base class to subscribe to the event instead of the page/pages that the user control is on. So basically the framework looks something like this....
User Control - Holds treeview
Web Page - Holds user control (Inherits Base Class)
Base Class - The Base Class for all web pages in the project (Inherits System.Web.UI.Page).
To further complicate things the base class is in a separate assembly and cannot reference the assembly that holds the user control and pages (this would cause circular dependency). I've tried to use Reflection and also tried using an Interface... Haven't had any luck with either... Currently the problem I am having is in the Base Class. I am trying to use System.Reflection.MethodInfo so I can create a delegate, but it requires the method to be static and making the method static makes it so MethodInfo can't find the method at all! This is driving me crazy... I've been working on it for a few days now... Any help would be greatly appreciated.
Currently, there isn't a lot of code since I recently wiped it out and started over... but here is the line that I am having issues with....
Code:
System.Reflection.MethodInfo mi = this.GetType().GetMethod("MyMethod",System.Reflection.BindingFlags.Static);
mi is coming back null. MyMethod is static. Also, when I make the method public instead of static the GetMethod command works but I need it to be static to create the delegate.
Kevin Davie
Consultant
Sogeti USA