b
should be a System.IO.StringWriter
. Your code in approach 1 should look like this:
var hControl = new HeaderControl();
var strWriter = new System.IO.StringWriter();
var htmlWriter = new System.Web.UI.HtmlTextWriter(strWriter);
hControl.Rendercontrol(htmlWriter);
string ControlAsString = strWriter.ToString();
This is copied from a piece of code I've written with help of another answers here in SO, and works perfectly for me.