Getting All HTML from the aspx page from code behind. RRS feed

  • Question

  • I am looking for a way to get all of the HTML from an aspx page from the .cs code behind. I have a need to get all data from the <html> tag to the </html> tag and then pass it on to a class. I have been looking all day for a way to do this and I am just running into roadblocks everywhere.

    Just to clarify. I have an aspx page that is showing various data items. I need all of the data including tags between the html tags. Something similar to JavaScripts document.GetElementsByTagName("html").outerHTML.

    Thanks for you help.


    Tuesday, November 2, 2010 12:07 AM


All replies

  • Hello,

    These kind of questions belong to the asp.net forum.

    I'm not quite sure what you really want, but you may refer to Control Adapters .

    You can do that using this technique.

    Also, it's not possible to that using client side scripting.

    Related Links:

    Asp.Net Control Adapters

    Control Adapter Architecture

    Eyal, Regards.

    • Proposed as answer by Mike Dos Zhang Thursday, November 4, 2010 2:31 AM
    • Marked as answer by Mike Dos Zhang Sunday, November 14, 2010 7:34 AM
    Tuesday, November 2, 2010 12:31 AM
  • Use WebClient.

          WebClient wc = new WebClient();
          string theHTML = wc.DownloadString("http://www.THE_WEB_PAGE.aspx");

    Noam B.

    Do not Forget to Vote as Answer/Helpful, please. It encourages us to help you...
    • Proposed as answer by Mike Dos Zhang Thursday, November 4, 2010 2:31 AM
    Tuesday, November 2, 2010 12:21 PM
  • Noam, that is an extra round-trip for no need, I already stated that it can be done using Control Adapters, It's much more efficient than downloading the page itself and parsing it afterwards.

    With the controls adapters you can change the output of the HTML, as well as manipulating it however you want before it reaches the client.

    Eyal, Regards.

    Tuesday, November 2, 2010 2:24 PM