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.