How to access child controls in panel control of custom web server control. RRS feed

  • Question

  • User561934832 posted

    I have a panel in Custom Web server Control. The panel is dynamically loaded with child controls. So I am unable to access the child controls(dynamically generated) of panel through controlscollection property.

    It is alway showing '0' count when I try to acces child controls of panel. Could you please help on how access dynamically generated controls of panel in User control.

    Monday, March 9, 2015 10:55 AM

All replies

  • User-760709272 posted

    Use FindControl


    Monday, March 9, 2015 11:08 AM
  • User561934832 posted

    I have the User Control in web application. I am able to find the other controls which are created in CreateChildControls(). But unable to find the dynamically added controls.

    By the below code, only the controls in panel are always 'null' .

    foreach(string key in this.Page.Request.Form.AllKeys)


            if (key != null)


                        Control oCtrl = Page.FindControl(key);                

              if (oCtrl != null)






    Monday, March 9, 2015 11:19 AM
  • User-760709272 posted

    Is this after a postback?  Are you re-creating the dynamic controls on each postback?  Controls you add yourself have to be re-added on each postback, they don't survive themselves.

    Monday, March 9, 2015 11:30 AM
  • User561934832 posted

    Ok. I am sure on how to recreate the dynamic controls on each postback.  As a Custom User Control, I which method I can recreate the dynmic controls. Could you please share some sample code on it....

    Monday, March 9, 2015 11:42 AM
  • User-1078840699 posted

    Hi Narayana,

    You can use id selector, since the ClientIDMode for radio button is not static you will have to use ClientID as the id generated by asp.net is not what you see as a server id.

    rbrbtnEn =  document.getElementById(('<%= rbtnEn.ClientID %>');

    To get the checked status

    alert(document.getElementById('<%= rbtnEn.ClientID %>').checked);
    Monday, March 23, 2015 5:45 PM