欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

asp.net实例代码protected override void Render(HtmlTextWriter writer)

程序员文章站 2023-03-14 14:57:33
protected override void render(htmltextwriter writer) { //把最终要输出的html压缩后再输出 stringwrit...
protected override void render(htmltextwriter writer)
{
//把最终要输出的html压缩后再输出
stringwriter html = new stringwriter();
htmltextwriter tw = new htmltextwriter(html);
base.render(tw);
string outhtml = html.tostring();
outhtml = regex.replace(outhtml, "\\s+", " ");
outhtml = regex.replace(outhtml, ">\\s+<", "><");
outhtml = outhtml.trim();
writer.write(outhtml);
}

protected override void render(htmltextwriter writer)
{
//最终输出前先存为html文件,如果发布最新信息了,可以打开一次default.aspx,然后他又会生成一次html

//这是默认的render实现,直接输出到writer中
//base.render(writer);
stringwriter html = new stringwriter();
htmltextwriter tw = new htmltextwriter(html);
//通过base.render()方法,把生成的html写入到我们定义的tw中
base.render(tw);
string path = server.mappath("index.html");
streamwriter sw = new streamwriter(path, false, system.text.encoding.default);
//写入到文件中
sw.write(html.tostring());
sw.close();
//写入到writer中,以输出页面的html
//注意,这里不能再调用base.render(writer),会出现错误
writer.write(html.tostring());
}