ChildControl childcontrol is null when called from Main control

I have built a webusercontrol in asp.net that contains a dropdown of data. When I directly place this control on the web form, it works well. But if I try to add this control as childcontrol to another control at runtime

Childcontrol childcontrol = new Childcontrol ();
maincontrol.controls.add(childcontrol)

      

the dropdown child control is not set (equal to null), so I am throwing an exception while trying to bind data to the dropdown.

0


source to share


1 answer


If it's a custom control (do you have an ascx file?), You need to use LoadControl to have ASP.NET create objects.



0


source







All Articles