<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/atom.xsl" media="screen"?><feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en-US"><title type="html">António Ribeiro's WebLog</title><subtitle type="html">Developer Consultant, Microsoft.</subtitle><id>http://blogs.msdn.com/aribeiro/atom.xml</id><link rel="alternate" type="text/html" href="http://blogs.msdn.com/aribeiro/default.aspx" /><link rel="self" type="application/atom+xml" href="http://blogs.msdn.com/aribeiro/atom.xml" /><generator uri="http://communityserver.org" version="2.1.61025.2">Community Server</generator><updated>2005-01-11T19:05:00Z</updated><entry><title>Creating HTML markup using HTML Controls object model</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/aribeiro/archive/2005/01/19/355972.aspx" /><id>http://blogs.msdn.com/aribeiro/archive/2005/01/19/355972.aspx</id><published>2005-01-19T16:00:00Z</published><updated>2005-01-19T16:00:00Z</updated><content type="html">&lt;P&gt;&lt;FONT face=Arial size=2&gt;Although ASP.NET provides a great object model for handling Web Controls and HTML Controls, I often see code that creates HTML markup directly, by manipulating strings. &lt;/FONT&gt;&lt;FONT face=Arial size=2&gt;An example:&lt;/FONT&gt;&lt;/P&gt;&lt;FONT face="Courier New" size=2&gt;
&lt;P&gt;&lt;FONT face="Courier New" size=2&gt;&amp;nbsp;&amp;nbsp;private string GetSomeHtml()&lt;BR&gt;&amp;nbsp;&amp;nbsp;{&lt;BR&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;&lt;FONT face="Courier New"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; string html = "&amp;lt;A HREF=\"&lt;FONT color=#000000&gt;http://blogs.msdn.com/aribeiro\&lt;/FONT&gt;"&amp;gt;" + Server.HtmlEncode("Antonio Ribeiro's Web Log") + "&amp;lt;/A&amp;gt;";&lt;BR&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; return html;&lt;BR&gt;&amp;nbsp;&amp;nbsp;}&lt;/FONT&gt;&lt;/P&gt;&lt;/FONT&gt;&lt;/FONT&gt;
&lt;P&gt;&lt;FONT face=Arial size=2&gt;Despite being performant, this isn't easy to read or to maintain.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Arial size=2&gt;You should allways take advantage of templated HTML and Web Controls in Visual Studio.NET. If you need&amp;nbsp;programmatically manipulate and HTML&amp;nbsp;element, drag an HTML Control into your Web Form, right click it&amp;nbsp;and select &lt;STRONG&gt;Run As Server Control&lt;/STRONG&gt;. Your HTML control is now a server side component that can be manipulated using ASP.NET code.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Arial size=2&gt;Still, if you need to create HTML markup strings in your code and you don't want to do it using templated controls, you can always use the HTML Object Model. Here's an example.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT size=2&gt;&lt;FONT face="Courier New"&gt;&amp;nbsp;&amp;nbsp;private string GetSomeHtml()&lt;BR&gt;&amp;nbsp;&amp;nbsp;{&lt;BR&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size=2&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;HtmlAnchor a = new HtmlAnchor();&lt;BR&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;a.HRef = "http://blogs.msdn.com/aribeiro";&lt;BR&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;a.InnerText = "Antonio Ribeiro's Web Log";&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;BR&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;HtmlTextWriter htw = new HtmlTextWriter(new StringWriter());&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; a.RenderControl(htw);&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return htw.InnerWriter.ToString();&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;BR&gt;&amp;nbsp;&amp;nbsp;}&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Arial size=2&gt;Another example, using the Render event:&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size=2&gt;&amp;nbsp;&amp;nbsp;protected override void Render(System.Web.UI.HtmlTextWriter writer)&lt;BR&gt;&amp;nbsp;&amp;nbsp;{&lt;BR&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;&lt;FONT face="Courier New"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;HtmlAnchor a = new HtmlAnchor();&lt;BR&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;a.HRef = "http://blogs.msdn.com/aribeiro";&lt;BR&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;a.InnerText = "Antonio Ribeiro's Web Log";&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; a.RenderControl(writer);&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;BR&gt;&amp;nbsp;&amp;nbsp;}&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT size=2&gt;&amp;nbsp;&lt;/P&gt;&lt;/FONT&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=355972" width="1" height="1"&gt;</content><author><name>aribeiro</name><uri>http://blogs.msdn.com/members/aribeiro.aspx</uri></author></entry><entry><title>New articles available !</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/aribeiro/archive/2005/01/11/350790.aspx" /><id>http://blogs.msdn.com/aribeiro/archive/2005/01/11/350790.aspx</id><published>2005-01-12T03:05:00Z</published><updated>2005-01-12T03:05:00Z</updated><content type="html">&lt;p&gt;&lt;font face="Arial" size="2"&gt;Check&amp;nbsp;&lt;font color="#006666"&gt;&lt;a href="http://blogs.msdn.com/aribeiro/articles/350773.aspx"&gt;Creating a Custom Placeholder to render and edit XML data using XSL templates&lt;/a&gt;&lt;/font&gt;&lt;/font&gt;&lt;font face="Arial" size="2"&gt;&amp;nbsp;(CMS) and &lt;/font&gt;&lt;font face="Arial" size="2"&gt;&lt;a href="http://blogs.msdn.com/aribeiro/articles/351439.aspx"&gt;Rendering n-column tables using the Repeater control&lt;/a&gt;&amp;nbsp;(ASP.NET)&lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font face="Arial" size="2"&gt;&lt;/font&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;&lt;font face="Arial" size="2"&gt;&lt;a href="http://blogs.msdn.com/aribeiro/articles/351439.aspx"&gt;&lt;/a&gt;&lt;/font&gt;&amp;nbsp;&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=350790" width="1" height="1"&gt;</content><author><name>aribeiro</name><uri>http://blogs.msdn.com/members/aribeiro.aspx</uri></author></entry></feed>