I’ve got a User Control with Save and Cancel buttons that I’m displaying in another user control. When the user hits Save, I want the inner user control to do it’s standard functionality but I would also like the parent control to do some things. What’s the best way to handle this?
Share
The best approach is raising a custom save-event that you can handle in the “outer” control.
http://www.codeproject.com/Articles/8797/Mastering-Page-UserControl-Communication#4.3
The advantage of this event-approach is that UserControls remain being reusable. You can use UserControl A in other pages(or UserControls) as well even when they don’t handle this event. It’s part of the controller to decide what is needed and what should be done.
UserControls as a rule should not depend on specific controllers, otherwise they are hard-linked and not reusable. That would be also a good source for nasty erros. A UserControl might be a controller for other nested (User-)Controls but not for the page itself.
Communication Summary: