title: Get the final generated html source using c# or vb.net
body: <p>using VB.net or c#, How do I get the generated HTML source?</p>
  
  <p>To get the html source of a page I can use this below but this wont get the generated source, it won't contain any of the html that was added dynamically by the javascript in the browser. How do I get the the final generated HTML source?</p>
  
  <p>thanks</p>
  
  <pre><code>WebRequest req = WebRequest.Create("http://www.asp.net"); 
  WebResponse res = req.GetResponse(); 
  StreamReader sr = new StreamReader(res.GetResponseStream()); 
  string html = sr.ReadToEnd();
  </code></pre>
  
  <p>if I try this below then it returns the document with out the JavaScript code injected</p>
  
  <pre><code>Public Class Form1
  
      Dim WB As WebBrowser = Nothing
  
      Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
  
          WB = New WebBrowser()
          Me.Controls.Add(WB)
          AddHandler WB.DocumentCompleted, AddressOf WebBrowser1_DocumentCompleted
  
  
          WB.Navigate("mysite/Default.aspx")
  
      End Sub
  
      Private Sub WebBrowser1_DocumentCompleted(sender As Object, e As WebBrowserDocumentCompletedEventArgs)
  
  
          'Dim htmlcode As String = WebBrowser1.Document.Body.OuterHtml()
          Dim s As String = WB.DocumentText
  
      End Sub
  End Class
  </code></pre>
  
  <p>HTML returned</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  
  &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
  &lt;head runat="server"&gt;
      &lt;title&gt;&lt;/title&gt;
  
  &lt;/head&gt;
  &lt;body&gt;
      &lt;form id="form1" runat="server"&gt;
      &lt;div id="center_text_panel"&gt;
      //test text  this text should be here
      &lt;/div&gt;
      &lt;/form&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  
      &lt;script type="text/javascript"&gt;
  
          document.getElementById("center_text_panel").innerText = "test text";
  
  
      &lt;/script&gt;
  </code></pre>