I wanted to dynamically add my user control as a child to another control.
I’ve used the code with new constructor, as I did for standard ASP.NET server controls and custom controls.
Dim ctrlInstances As SearchAreasInstancesUsc = new SearchAreasInstancesUsc() ‘Incorrect
Then I found that declaratively defined( in ASCX markup) controls are not initialized and set to null.
Of course, I should LoadControl to allow ASP.NET to initialize all declarations.
Dim ctrlInstances As SearchAreasInstancesUsc = LoadControl(“SearchAreaInstancesUsc.ascx”) ‘correct
UPDATE: I strongly recommend to read a great atricle: TRULY Understanding Dynamic Controls -Parts 1-4.
(See also related Rendering ASP.NET Controls out of order and Rendering ASP.NET Controls out of place)