Render aspx page as a string

To render a page into a string use a StringWriter object.  This can be useful when making AJAX type of queries.  Using an aspx page for AJAX calls makes it easy to reference session state information.

 

        System.IO.StringWriter htmlStringWriter = new System.IO.StringWriter();

        Server.Execute("Page.aspx", htmlStringWriter);

        string htmlOutput = htmlStringWriter.GetStringBuilder().ToString();

Published Saturday, February 14, 2009 1:14 AM by Kiyoshi

Comments

# re: Render aspx page as a string

Tuesday, June 16, 2009 1:48 PM by smithouse

Nice work.  When my user clicks on the submit button, I save the record and then run your code to email the form.  But when it gets to the 2nd line, Server.Execute..., it starts an endless loop of executing the submit code over and over.  Any idea how to get around this?  Thanks

Leave a Comment

(required) 
(required) 
(optional)
(required)