title: How to create ASP.NET labels multiple times by clicking a button multiple times
body: <p>I want to display text multiple times if the user clicked the button multiple times. Like for example, if I clicked the button fourth time, I want four text to appear. However, there is an issue going on that prevents it from appearing multiple times.</p>
  
  <p>I was expecting it to appear like this if the user press the button three times:</p>
  
  <pre><code>Hello world
  Hello world
  Hello world
  </code></pre>
  
  <p>But it showed me this:</p>
  
  <pre><code>Hello world
  </code></pre>
  
  <p>Is there anyone can help me with this problem....</p>
  
  <p>Here's the source code:</p>
  
  <p>Webform1.aspx</p>
  
  <pre><code>&lt;%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs"  Inherits="addlabels.WebForm1" %&gt;
  
  &lt;!DOCTYPE html&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;
          &lt;asp:Panel ID="Panel1" runat="server"&gt;&lt;/asp:Panel&gt;
          &lt;asp:Button ID="add" runat="server" Text="Add more" OnClick="add_click"/&gt;
  
      &lt;/div&gt;
      &lt;/form&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>WebForm1.aspx.cs</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Web;
  using System.Web.UI;
  using System.Web.UI.WebControls;
  
  using System.Diagnostics;
  using System.Text;
  
  namespace addlabels
  {
      public partial class WebForm1 : System.Web.UI.Page
      {
  
          int pressNumberOfTimes;
  
          protected void Page_Load(object sender, EventArgs e)
          {
  
          }
  
  
          protected void add_click(object sender, EventArgs e)
          {
              // Add the panel
              pressNumberOfTimes++;
  
              Label lbl_homeCarouselAdd = new Label();
  
              // Set the label's Text and ID properties.
              lbl_homeCarouselAdd.ID = "lbl_homeCarouselAdd" + pressNumberOfTimes;
  
              StringBuilder strDiv = new StringBuilder();
              strDiv.Append(string.Format(@"&lt;p class='style'&gt;Hello world&lt;/p&gt;"));
  
              lbl_homeCarouselAdd.Text = strDiv.ToString();
  
  
              Panel1.Controls.Add(lbl_homeCarouselAdd);
          }
      }
  }
  </code></pre>