Rendering a page Without openning it in a Window

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
 
G

Giorgio Parmeggiani

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
 
H

HVG

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.
 
R

Rajesh.V

Just do HttpRequest to the page. The httprequest.response will contain the
html.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,763
Messages
2,569,562
Members
45,038
Latest member
OrderProperKetocapsules

Latest Threads

Top