title: Get User Control HTML
body: <p>I need to get the HTML of a user control.</p>
  
  <p>At the moment I am using below code.</p>
  
  <pre><code>// Approach 1
  HeaderControl hControl = new HeaderControl();
  
  StringBuilder b = new StringBuilder();
  HtmlTextWriter h = new HtmlTextWriter(new StringWriter(b));
  
  hControl.RenderControl(h);
  string controlAsString = b.ToString();
  
  // controlAsString  is "" -- Doesn't work
  
  // ----------------------------------------------
  // Approach 2
  UserControl uc = new UserControl();
  HeaderControl hc = (HeaderControl)uc.LoadControl("~/Views/HeaderControl.ascx");
  
  hControl.RenderControl(h);
  string controlAsString = b.ToString();
  
  // controlAsString = "&lt;h3&gt;test data&lt;/h3&gt;  - Works.
  </code></pre>
  
  <p>Can you please explain how I can achieve this using the approach 1 So that I dont have to hard code the virtual path of the control.</p>
  
  <p>I have also tried the other overload of the uc.LoadControl()</p>
  
  <pre><code>UserControl uc = new UserControl();
  HeaderControl hControl = (HeaderControl)uc.LoadControl(typeof(HeaderControl), null);
  
  // Header control has a default constructor that takes no parameters
  
  // but no luck :(
  </code></pre>