locked
Render an aspx page into a string RRS feed

  • Question

  • User599138732 posted

    Hello!

    This is pretty urgent so I really appreciate any fast answers.

    I need to create a web service that will:

    1. Dynamically load an ASPX page (or user control).

    2. Render all the HTML into a string.

    3. Return the HTML.

    I do not use postbacks in our pages since they will all be chached by Akamai.

    I just need to use ASP.NET 2.0 to render the pages to HTML.

    So, from a web service, so how can I dinamically load a Page and render it to HTML? This aspx page will be stored in a class library to which my web service has access to. The idea is that the aspx page will be pre-compiled and I will instantiate a page and then make it execute and get the HTML results into a string. How?

    Thanks!

    David

    Friday, June 29, 2007 10:17 AM

Answers

  • User-1290177837 posted

    Try to use Render method of Page class. After, applies HtmlTextWriter argument to StringWriter and, finally, return StringWriter.ToString() to your function.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, June 29, 2007 10:56 AM

All replies

  • User-1290177837 posted

    Try to use Render method of Page class. After, applies HtmlTextWriter argument to StringWriter and, finally, return StringWriter.ToString() to your function.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, June 29, 2007 10:56 AM
  • User599138732 posted

    My problem is different. I am not executing within the life cycle of a page because what I am trying to do is to render a page without doing an HTTP request on it. I am trying to instantiate a Page from a class in my project object and render its controls into a string.

    Basically I would like to take the web server out of the equation and just instantiate a page and render it to get its HTML, how can I do this?

    Thanks for any ideas.

    David

    Tuesday, July 3, 2007 9:58 PM
  • User-1290177837 posted

    Maybe if you don´t to create a Page, but HtmlTextWriter in you class. Then you to create all code Page in it. Finally, you render it to a StringWriter and return string with StringWriter.ToString() to WebMethod. But you don´t access to Session Object and all that objects of Page or IIS.

    Good luck. Tell me if you get you goal.

    Wednesday, July 4, 2007 7:59 AM