asp.net - How to find nested controls within nested user controls -



asp.net - How to find nested controls within nested user controls -

i have user command (control1) has placeholder may contain several additional user controls (of same type - see below) added dynamically. how navigate user command hierarchy find values of nested sets of controls when button located in command 1 clicked?

control 1:

<%@ command language="c#" autoeventwireup="true" codebehind="control1.ascx.cs" inherits="control1" %> <%@ reference control="control2.ascx" %> <div id="div1"> <div id="divph"><asp:placeholder id="phcontrols" runat="server" /></div> <div id="divcontinue"><asp:button id="btncontinue" text="continue" onclick="submit_click" runat="server" /></div> </div>

code behind control1.aspx:

protected void submit_click(object sender, eventargs e) { // iterate through list of divcontrol2 controls , find out radio button selected // example, there may 3 divcontrol2's added placeholder on control1, rdobth1 might selected on 2 of controls // , rdobtn2 might selected on 1 - how navigate command structure? }

control 2 (several of these may added placeholder on control1):

<%@ command language="c#" autoeventwireup="true" codebehind="control2.ascx.cs" inherits="control2" %> <div id="divcontrol2"> <p><strong><asp:radiobutton id="rdobtn1" groupname="group1" checked="true" runat="server" /> check this</strong></p> <p><strong><asp:radiobutton id="rdobtn2" groupname="group1" checked="false" runat="server" /> no, check one</strong></p> </div>

check below code , allow me know if have queries.

protected void submit_click(object sender, eventargs e) { (int count = 0; count < phcontrols.controls.count; count++) { usercontrol uc = (usercontrol)(phcontrols.controls[count]); if (uc != null) { radiobutton rdobtn1 = new radiobutton(); radiobutton rdobtn2 = new radiobutton(); rdobtn1 = (radiobutton)(uc.findcontrol("rdobtn1")); rdobtn2 = (radiobutton)(uc.findcontrol("rdobtn2")); if (rdobtn1.checked == true) { response.write("1st checked "); } else if (rdobtn2.checked == true) { response.write("2nd checked"); } } }

asp.net user-controls nested

Comments

Popular posts from this blog

iphone - Dismissing a UIAlertView -

c# - Can ProtoBuf-Net deserialize to a flat class? -

javascript - Change element in each JQuery tab to dynamically generated colors -