Rendering a page Without openning it in a Window

  • Thread starter Thread starter HVG
  • Start date Start date
H

HVG

Hi, is it possible to render a whole page (ie. a aspx webform) to a string
_without_ actually loading the page in a window? Eg if Iam executing
page1.aspx at the server, I would then like to render page2.aspx to a string
_without_ returning to the client.

I currently happily override the Render property of a page and capture its
html that way, but so far this requires me to postback to the client and
open the page in a little window, render it to a string and save it to
Session, then immediately close the window. It creates a "flash" on the
screen & it looks bad (and is slow too)

I can see how to render a individual server control and capture its html at
any time, but I can't see how to do the same for a whole page/webform. I
have reports that will both be used for displaying info on a browser and for
sending html via email.

Thanks for any help!
Hugo
 
Hi
Hi, is it possible to render a whole page (ie. a aspx webform) to a string
_without_ actually loading the page in a window? Eg if Iam executing

Try this:

StringWriter stringWriter = new StringWriter();
HtmlTextWriter htmlWriter = new HtmlTextWriter(stringWriter);
Page.RenderControl(htmlWriter);
string output = stringWriter.ToString();

Hi
Giorgio
 
Thanks for the reply, but I can't see how to make the page to be rendered
(the "Page" obj in your code) the webform I wish to render.
My senario is that from the code in page1.aspx, I wish to render page2.aspx
(ie. a totally a different page) to html.
Am I making any sense?! Thanks.
 
Back
Top