title: Converting contents of HtmlTextWriter to a string
body: <p>I have a third party tool that creates an img tag through code using HtmlTextWriter's RenderBeginTag, RenderEndTag &amp; AddAttribute methods. I want to get the resulting HTML into a string. 
  I tried the reflection method mentioned <a href="https://stackoverflow.com/questions/1008551/htmltextwriter-to-string-am-i-overlooking-something">here</a> but I get a  error "Unable to cast object of type 'System.Web.HttpWriter' to type 'System.IO.StringWriter". The  InnerWriter type of the HtmlTextWriter is of type HttpWriter.</p>
  
  <p>Any ideas on how to copy the output html into a string?</p>
  
  <p><strong>Addition:</strong> code from third party control</p>
  
  <pre><code>protected override void Render( HtmlTextWriter output )
    {
    .....
    output.AddAttribute( HtmlTextWriterAttribute.Src, src );
    output.RenderBeginTag( HtmlTextWriterTag.Img );
    output.RenderEndTag();
                  &lt;-- What is the HTML now? Maybe look in OnPreRenderComplete event?
  
    }
  </code></pre>