title: Render User Control and Fire Control Events
body: <p>I'm trying to load a user control in code and store the output as a string variable. At the moment I've got the below code:</p>
  
  <pre><code>StringWriter sw = new StringWriter();
  HtmlTextWriter htw = new HtmlTextWriter(sw);
  
  WidgetControlBase widget = (WidgetControlBase)LoadControl("/controls/mycontrol.ascx");
  widget.RenderControl(htw);
  </code></pre>
  
  <p>The problem is that the <code>RenderControl</code> method doesn't fire any of the control events so anything I add in the control <code>Page_Load</code> doesn't happen.</p>
  
  <p>I've tried loading the control in a <code>PlaceHolder</code> and then rendering the <code>PlaceHolder</code> like so:</p>
  
  <pre><code>StringWriter sw = new StringWriter();
  HtmlTextWriter htw = new HtmlTextWriter(sw);
  
  WidgetControlBase widget = (WidgetControlBase)LoadControl("/controls/mycontrol.ascx");
  
  myPlaceholder.Controls.Add(widget);
  myPlaceholder.RenderControl(htw);
  </code></pre>
  
  <p>However this seems to do the same as just using <code>RenderControl</code> direct on the control, it doesn't fire any events either.</p>
  
  <p>Is there a way I can get a string containing the contents of my control while still firing the control events?</p>