title: Programmatically adding a user control in Sharepoint 2010
body: <p>I'm trying to add a custom user control to  a Panel in a visual web part in Sharepoint 2010, with the following lines of code:</p>
  
  <p><code>
  MyUserControl userControl = new MyUserControl();</p>
  
  <p>MainContentPanel.Controls.Add(userControl);
  </code></p>
  
  <p>However, my user control fails to load/render. The above code is triggered by clicking a link button.</p>
  
  <p>Am I missing something, or is it just not possible to do it this way?</p>