title: Creating HTMLControls versus outputting a string of HTML
body: <p>I was recently trying to explain to a programmer why, in ASP.Net, they should create HTMLControls instead of creating HTML strings to create Web pages.</p>
  
  <p>I know it is a better way of doing things, but I really couldn't give concrete reasons, other than, "This way is better."</p>
  
  <p>If you had to answer this question, what would your answer be?</p>
  
  <p>Why is <pre>Dim divA as New HtmlControls.HtmlGenericControl("div") 
  Dim ulList1 as New HtmlControls.HtmlGenericControl("ul") 
  Dim liObj1, liObj2, liObj3 as New HtmlControls.HtmlGenericControl("li") 
  liObj1.innerText = "List item 1" 
  liObj2.innerText = "List item 2"
  liObj3.innerText = "List item 3"
  ulList1.Controls.Add(liObj1)
  ulList1.Controls.Add(liObj2)
  ulList1.Controls.add(liObj3)
  divA.Controls.add(ulList1)</pre></p>
  
  <p>"better" than:  </p>
  
  <pre><code>Dim strHTML as String
  strHTML = "&lt;div&gt;&lt;ul&gt;&lt;li&gt;List item 1&lt;/li&gt;&lt;li&gt;List item 2&lt;/li&gt;&lt;li&gt;List item 3&lt;/li&gt;&lt;/ul&gt;&lt;/div&gt;"
  </code></pre>
  
  <p>?  It doesn't look better.  Look at all that code!  And, this is a very simplistic example, to save space.  I don't think I would ever actually create a list manually like that, but would be iterating through a collection or using a more advanced Web control, but I'm trying to illustrate a point.</p>