title: How to return HTML controls generated by a function as a text string containing the HTML markup
body: <p>I am trying to generate some HTML code from a VB.NET Web Method and return it as text.</p>
  
  <p>Here's an example markup:</p>
  
  <pre><code>&lt;ul&gt;
      &lt;li&gt;234: this is an item&lt;/li&gt;
      &lt;li&gt;456: another item&lt;/li&gt;
  &lt;/ul&gt;
  </code></pre>
  
  <p>I have some VB thus:</p>
  
  <pre><code>Dim rList As New HtmlGenericControl("UL") ' &lt;&lt; create an HTML list container
  
      Try ' looping through a dictionary of item data
           For j = 0 To UBound(d("itemNo")) ' loiop through all individual item data
               Dim Item = d("itemNo")(j)
               Dim itemName =  d("itemName")(j)
               Dim liItem As New HtmlGenericControl("li") ' &lt;&lt; creates an HTML list item
               liItem.InnerHtml += itemNo &amp; ":" &amp; itemName 
               rList.InnerHtml += liItem 
           Next
       Catch ex as Exception
           ' fail case
       End Try
  </code></pre>
  
  <p>Now, this will generate all the HTML tags and content perfectly well. If I were writing this out to a page, I could do that quite simply.</p>
  
  <p>BUT... I don't want to do that, I want to somehow return the actual HTML markup created by the above code as a text string, ie, I want <code>return rList.toString()</code> to return the markup, but instead it just returns the object type as a string.</p>
  
  <p>I could do this without bothering with the <code>HtmlGenericControl</code> class at all and simply generate a whole load of strings with the opening and closing HTML tags, but the rest of this code is quite complex and there's plenty of room for error... if I could achieve what I am looking for above it'd be much simpler to code!</p>