I have an ASP.NET Web Forms page childPage.aspx
with masterPage.aspx
as the master page. The childPage.aspx
has a user control (userControl.ascx
) control defined on it. Now, I am trying to access the controls on childPage.aspx
from within the user control. I have tried a handful of different approaches:
HtmlContainerControl ProductMenu = (HtmlContainerControl)Page.FindControl("ProductMenu");
HtmlContainerControl ProductMenu = (HtmlContainerControl)this.Page.FindControl("ProductMenu");
HtmlContainerControl ProductMenu = (HtmlContainerControl)Parent.FindControl("ProductMenu");
HtmlContainerControl ProductMenu = (HtmlContainerControl)this.Parent.parent.FindControl("ContaintHolder").FindControl("ProductMenu")
In above code, ProductMenu
is the id
of the <div runat="server" />
on childPage.aspx
. Now, I am trying to access it from within my user control, but that fails to return the div
.
Please help me out. How should I do this? Thanks in advance.