通过流阅读器保存html内容? [英] Saving html content via a streamreader?

查看:79
本文介绍了通过流阅读器保存html内容?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有一种方法可以将aspx页面的html内容保存在cs文件的pageload部分中,并在回发时再次将其加载?

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 streamreader write the content back in?

如果有的话,有人有例子吗?

If so does anyone have any examples?

推荐答案

您的意思是这样吗,通过覆盖 Render 方法来捕获生成的HTML?

Do you mean something like this, capturing the generated HTML by overriding the Render method?

protected override void Render(HtmlTextWriter writer)
{
    string pageSource;

    // setup a TextWriter to capture the markup
    using (var sw = new StringWriter())
    using (var htw = new HtmlTextWriter(sw))
    {
        // render the markup into our surrogate TextWriter
        base.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
}

这篇关于通过流阅读器保存html内容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆