C# – ASP.NET User Controls Cross-Communication


The scenario: 2 user controls (foo.ascx and fum.ascx)

foo has a method that would really like to access a property from fum. They live on the same page, but I can't find a very simple way to accomplish this sort of communication.

Any ideas?

Best Solution

  • Add an event OnMyPropertyValueChanged in fum.ascx.
  • Add the corresponding EventHandler to foo.ascx which stores the property value in a private variable.
  • Attach the event handler of foo.ascx to the event of fum.ascx on Page_Load.
  • Raise the event on fum.ascx Page_Load and whenever needed
  • Let the method of foo.ascx use its own variable