I have 5 user controls on the page and each control implements it's own interface that contains properties and events. In order to enable communication between user controls, I am creating a property of target user control inside other user control. Through this property, it's state can be altered and be able to register its events.
Below is the pseudo code of results user control. It subscribes to OnSearch event of Search user control.
public interface IResults { //other fields ISearch SearchControl { get;} } public partial class Results : IResults { //other fields public ISearch SearchControl { get{ this.Page.Parent.FindControl("UCSearch") as ISearch;} } protected override void Page_Load(object sender, EventArgs e) { this.SearchControl.OnSearch += new EventHandler(testMethod); } } Is it ok to have the reference properties inside user controls to subscribe to the events and manipulating the state. Does it create any maintenance problem in future.
Does FindControl and type casting degrade the performance of the application.
UserControls access each other this way. This would be a simple[Import]with MEF, but that would have far larger complications.UserControls. I'd probably make some kind of communication class for it, though.