I have two user controls A and B, where B depends on the existence of A in the same page.
I’m trying to implement some functionality like this:
<mine:A ID="IdOfTheAControl" runat="server" />
<mine:B BelongsTo="IdOfTheAControl" runat="server" />
I’m able to extract "IdOfTheAControl" but unable to get the actual control with that ID. I tried to use FindControl("IdOfTheAControl") in Page_Load for B but this returns null, probably because the function looks for the control in B.ascx and not the master page where the two controls are siblings.
How do I, from a user control, get access to another user control with a given ID if the two controls are siblings in a page?
Since user controls inherit from System.Web.UI.WebControl, they have a Page and Parent property. The Page will give you a handle to the page and Parent a handle to the control that hosts your control if there are nested controls.
try mineB.Page.FindControl(“IdOfTheAControl”); //pseudo code