title: Visual Web Developer Replace Inner HTML With New HTML
body: <p>I have made a web page to display a graphic and then allow the user to enter some comments underneath it.  The user is prompted for input and I am trying to store each comment in a List and then display the list as an ordered HTML list.  Here is the relevant code:</p>
  
  <pre><code>&lt;script runat="server"&gt;
  
  private List&lt;string&gt; messages = new List&lt;string&gt;();
  
  protected void Button2_Click(object sender, EventArgs e)
  {
      messages.Add(TextBox2.Text);
      TextBox2.Text = "";
  }
  
  protected void Button3_Click(object sender, EventArgs e)
  {
      messages.Clear();
  }
  
  protected void Button4_Click(object sender, EventArgs e)
  {
      string output = "&lt;ol&gt;";
      foreach (string message in messages)
      {
          output += "&lt;li&gt;";
          output += message;
          output += "&lt;/li&gt;";
      }
      output += "&lt;/ol&gt;";
      Message.InnerHtml = Server.HtmlEncode(output);
  }
  
  protected void Chart1_Load(object sender, EventArgs e)
  {
  
  }
  
  &lt;/script&gt;
  
  &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
  &lt;head runat="server"&gt;
      &lt;title&gt;&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
      &lt;form id="form1" runat="server"&gt;
      &lt;div&gt;
          Key Messages:&lt;br /&gt;
          &lt;span id="Message" runat="server"&gt;
              &lt;asp:TextBox runat="server" ID="TextBox2" Width="500px"&gt;&lt;/asp:TextBox&gt;
              &lt;asp:Button runat="server" ID="Button2" Text="Enter Message" Onclick="Button2_Click" /&gt;
              &lt;asp:Button runat="server" ID="Button3" Text="Clear Messages" onclick="Button3_Click" /&gt;
              &lt;asp:Button runat="server" ID="Button4" Text="Done" onclick="Button4_Click" /&gt;
          &lt;/span&gt;
      &lt;/div&gt;
      &lt;/form&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>The output from this is:</p>
  
  <pre><code>Key Messages:
  &lt;ol&gt;&lt;/ol&gt;
  </code></pre>
  
  <p>So I have two mysteries:</p>
  
  <p>1)  Why isn't the text being entered into the textbox being added to the list</p>
  
  <p>2)  Why is the new HTML being displayed as plain text.</p>
  
  <p>Any advice is appreciated.</p>
  
  <p>Regards.</p>