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

夏日的草原,早晨空气格外清新,我缠着父亲在草原上漫步。幽幽的草香迎面拂来,红艳艳。朝阳正从地平线上冉冉升起,为辽阔的草原镀上一层金色。草叶上的露珠,像镶在翡翠上的珍珠,闪着五颜六色的光华。我看到草丛中夹着许多粉红色、白色、黄色或是蓝色的不知名的花,把草原装扮得十分美丽。
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());
}

本文asp.net实例代码protected override void Render(HtmlTextWriter writer)到此结束。日子总是像从指尖渡过的细纱,在不经意间悄然滑落。那些往日的忧愁和误用伤,在似水流年的荡涤下随波轻轻地逝去,而留下的欢乐和笑靥就在记忆深处历久弥新。小编再次感谢大家对我们的支持!

您可能有感兴趣的文章
C# new和override的区别分析