I was able to resolve this, for anyone wondering, I had put the call to EnsureChildControls() in the wrong location in my Control's class, I moved it to OnInit and it worked fine, the control previously was not getting created in time for the Page_Load to pick it up, moving it helped, now the control is there when the Page_Load section runs.
On Sep 20, 10:48 am, soni2926 <[email protected]> wrote: > I'm having issues trying to get access to a control within my > Templated Control, which is within a Master page. > > How do I get access to the below linkButton control from my Master > page or a page using that Master, this is in my Master page: > <Project:RoleControl ID="RoleControl1" runat="server"> > <AdminTemplate> > <li id="liadmin" runat="server"><asp:LinkButton id="lnkAdmin" > PostBackUrl="~/admin/admin.aspx" runat="server" > CausesValidation="false">Admin</asp:LinkButton></li> > </AdminTemplate> > </ Project:RoleControl> > > Basically it’s a templated control (inherits from WebControl, > INamingContainer) I built which will allow me to show certain things > only to admin users, we are not using asp.net membership so I came up > with a control that works. But when I try to access it within the > Master page itself it keeps saying the control has 0 count in it, I’m > doing this check in the Page_Load event: > > if (RoleControl1.Controls.Count > 0) > { > string roleControlId = RoleControl1.Controls[0].ID; > > ((HtmlGenericControl)RoleControl1.FindControl(roleControlId)).Attributes["class"] > = "navselected"; > > } > > But the RoleControl1.Controls.Count check is always 0. I know the > control is rendering as I can see it when the page loads, the link > comes up. I thought maybe I’m checking it in the incorrect event, > rather than Page_Load should I be checking for it in another event, > could it be that at that point the control is not populated? > > Also how would I access the same control from another page, which > uses the Master Page that has the control in it? > > Thanks.
