惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

酷 壳 – CoolShell
酷 壳 – CoolShell
T
Threatpost
Latest news
Latest news
N
News | PayPal Newsroom
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Help Net Security
Help Net Security
D
Darknet – Hacking Tools, Hacker News & Cyber Security
AI
AI
Simon Willison's Weblog
Simon Willison's Weblog
TaoSecurity Blog
TaoSecurity Blog
The Last Watchdog
The Last Watchdog
L
LINUX DO - 热门话题
Google DeepMind News
Google DeepMind News
T
Threat Research - Cisco Blogs
O
OpenAI News
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
T
The Exploit Database - CXSecurity.com
NISL@THU
NISL@THU
Application and Cybersecurity Blog
Application and Cybersecurity Blog
S
Securelist
小众软件
小众软件
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Martin Fowler
Martin Fowler
S
SegmentFault 最新的问题
Cisco Talos Blog
Cisco Talos Blog
云风的 BLOG
云风的 BLOG
AWS News Blog
AWS News Blog
GbyAI
GbyAI
N
News and Events Feed by Topic
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
美团技术团队
Engineering at Meta
Engineering at Meta
A
About on SuperTechFans
博客园 - 三生石上(FineUI控件)
S
Schneier on Security
博客园 - 聂微东
V2EX - 技术
V2EX - 技术
T
Troy Hunt's Blog
SecWiki News
SecWiki News
S
Secure Thoughts
B
Blog RSS Feed
Hugging Face - Blog
Hugging Face - Blog
WordPress大学
WordPress大学
腾讯CDC
H
Heimdal Security Blog
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
Apple Machine Learning Research
Apple Machine Learning Research
月光博客
月光博客
www.infosecurity-magazine.com
www.infosecurity-magazine.com
P
Privacy International News Feed

博客园 - bestcomy

在OPENSUE 11.3 上安装 sysstat Upload bug in MOSS 2007 / Windows Server 2008 - bestcomy Excel列名转换 Clienside ProgressIndicator - bestcomy - 博客园 ASP.NET MVC 源代码发布! 微软项目组招聘.NET开发人员(北京) 欢迎访问我的新BLOG空间 SharePoint 胡言乱语 你觉得vs.net那些地方让你使用起来很不爽? Include javascript and css dynamically - bestcomy How to set value for webpart’s properties when I create a new sharepoint template Get the true value of a calculate field in SharePoint 调用自定义event时需要注意的一个问题 self==top 如何设置AD用户的"用户下次登陆时须更改密码"属性 (LDAP Provider) 微软 and 香烟 Cool!!! Virtual Earth Technology Preview sth about our coding life 还没有Windows Live Messenger的朋友看过来
Two ways to get HtmlTextWriter for HTML rendering
bestcomy · 2006-11-02 · via 博客园 - bestcomy

I need to render some html in my asp.net applications sometime, I chose HtmlTextWriter to build the html source because I can use those handy methods of this object such as RenderBeginTag, AddAttribute, and so on. I know two ways to do this.

 1 StringBuilder sb = new StringBuilder();
 2             using(StringWriter sw = new StringWriter(sb))
 3             {
 4                 using(HtmlTextWriter output = new HtmlTextWriter(sw))
 5                 {
 6                     output.RenderBeginTag(HtmlTextWriterTag.Table);
 7                     for(int y=0; y<1000; y++)
 8                     {
 9                         output.RenderBeginTag(HtmlTextWriterTag.Tr);
10                         for(int x=0; x<100; x++)
11                         {
12                             output.RenderBeginTag(HtmlTextWriterTag.Td);
13                             output.Write("&nbsp;");
14                             output.RenderEndTag();
15                         }
16                         output.RenderEndTag();
17                         output.Flush();
18                     }
19                     output.RenderEndTag();
20                     Response.Write(output.ToString());
21                 }
22             }

 1 using(MemoryStream stream = new MemoryStream())
 2             {
 3                 using(TextWriter tw = new StreamWriter(stream,System.Text.Encoding.UTF8) as TextWriter)
 4                 {
 5                     using(HtmlTextWriter output = new HtmlTextWriter(tw))
 6                     {
 7                         output.RenderBeginTag(HtmlTextWriterTag.Table);
 8                         for(int y=0; y<1000; y++)
 9                         {
10                             output.RenderBeginTag(HtmlTextWriterTag.Tr);
11                             for(int x=0; x<100; x++)
12                             {
13                                 output.RenderBeginTag(HtmlTextWriterTag.Td);
14                                 output.Write("&nbsp;");
15                                 output.RenderEndTag();
16                             }
17                             output.RenderEndTag();
18                         }
19                         output.RenderEndTag();
20                         output.Flush();
21                         Response.Write(output.ToString());
22                     }
23                 }
24             }