Saving Html Content Via A Streamreader?
Is there a way to save html content of an aspx page in the pageload part of the cs file and have it loaded again on postback? Maybe using a streamreader to save it then have the s
Solution 1:
Do you mean something like this, capturing the generated HTML by overriding the Render
method?
protectedoverridevoidRender(HtmlTextWriter writer)
{
string pageSource;
// setup a TextWriter to capture the markupusing (var sw = new StringWriter())
using (var htw = new HtmlTextWriter(sw))
{
// render the markup into our surrogate TextWriterbase.Render(htw);
// get the captured markup
pageSource = sw.ToString();
}
// render the markup into the output stream
writer.Write(pageSource);
// now you can do what you like with the captured markup in pageSource
}
Solution 2:
ASP.NET has an extensive caching mechanism which is meant to do what you describe
Solution 3:
Something along these lines HtmlTextWriter to String - Am I overlooking something? can be done. I've done it with the Render() method of the page, not the RenderContents method. I can't for the life of me remember why I did that, though. It may have been for versions of ASP.net before they introduced the ability to cache most of a page, except for small pieces. Unless you really need to do this, use the built in caching functionality.
Post a Comment for "Saving Html Content Via A Streamreader?"