Interface for Event Handler in ASP.NET
Posted on 2009-02-11
This is a difficult question to properly phrase.
I have a user control that is fairly complex in appearance - but I need it to be open ended in functionality. Specifically an event or two that it fires off based on a built in component.
I've tried inheriting from it to make a second control that wraps it for more specific means (the control needs to be used in several places, always looking the same, but behaving differently under the hood). This proved fruitless ,as while the code is preserved the HTML styling is not - which entirely defeats the purpose of wrapping the control to begin with.
So my thought was to try an interface. It's been a long time since I've worked with them, and I don't think I've ever done them with ASP.NET. But essentially this is the scenario.
Interface iEventHandlers needs to have an abstract event handler method that the wrapper user control implements, and whenever the child control that is embedded on that user control fires it's event, this interface event handler is fired and passed up to the parent control for handling.