Find a control in RoleGroup LoginView

I have text fields and checkboxes inside a RoleGroup LoginView. How can I access these controls in my code?

<asp:LoginView ID="lgvAdmin" runat="server"> <RoleGroups> <asp:RoleGroup Roles="Administrator"> <ContentTemplate> <div class="floatL"> <h1>Administrator Settings</h1> <asp:CheckBox ID="chkActive" Text="Is Active" Checked="false" runat="server" /><br /> <asp:CheckBox ID="chkIsRep" Text="Is Representative" Checked="false" runat="server" /> <br /><br /> <strong>User Permissions</strong><br /> <asp:RadioButtonList ID="RadioButtonList1" runat="server" RepeatDirection="Horizontal" RepeatColumns="3" Width="200" Font-Bold="true"> <asp:ListItem Value="User" Selected="True">User</asp:ListItem> <asp:ListItem Value="Administrator">Administrator</asp:ListItem> </asp:RadioButtonList><br /><br /> <strong>Assigned to Rep</strong><br /> <asp:DropDownList ID="DDLRep" CssClass="ddlStyle" Width="165" runat="server" /> </div> </ContentTemplate> </asp:RoleGroup> </RoleGroups> </asp:LoginView> 

I know that I need to use the FindControl method, and I also know that this is not just lgbvAdmin.FindControl ("chkIsRep") due to the hierarchy where the control is located.

So, it should be something like: lgvAdmin.controls [0] .FindControl ("chkIsRep");

How can I find the exact path to access the control?

+4
source share
1 answer

I know this is an old post, but here is a brief description of how to do this for everyone who needs an answer:

 ITemplate template = lgvAdmin.RoleGroups[0].ContentTemplate; if (template != null) { Control container = new Control(); template.InstantiateIn(container); foreach (Control c in container.Controls) { if (c is CheckBox) { //Do work on checkbox } } } 
+2
source

All Articles