Programatically loading user controls

Posted by PhilSando on Geeks with Blogs See other posts from Geeks with Blogs or by PhilSando
Published on Thu, 27 May 2010 08:41:48 GMT Indexed on 2010/05/27 10:02 UTC
Read the original article Hit count: 236

Filed under:

Today's little problem is that I am trying to load user controls from my codebehind like so:

Dim myControl As UserControl = Page.LoadControl("~\Modules\Content.ascx") 
           
Controls.Add(myControl) 

On running the page myControl is no where to be seen. I wonder why that is? Well after a bit of thought the following come to mind...

  1. Am I using the correct code to insert the usercontrol?
  2. Is there an alternative available?
  3. Does the fact that the usercontrol has a page_load method make a difference?
  4. Does the fact that the usercontrol is being called from the page_init method make a difference?
  5. Do I need to register the control in my aspx page at design time?

I'll be looking to answer these questions as the day goes on!

 

© Geeks with Blogs or respective owner