title: Problem in Dynamically adding dropdownlist in table (C#)
body: <p>I am doing a very simple task but i am stuck at one point. I want to create a simple page (ASP.NET with C#) which displays a button initially. When user clicks on the button then a dropdownlist should be added to the page dynamically. I am doing this through C#. My problem is that the list is added to the page first time but after that only page refreshes and no more list is added. I don't know whats going on. Here is my code:</p>
  
  <p>Default.aspx</p>
  
  <pre><code>    &lt;%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.master"  AutoEventWireup="true"
      CodeFile="Default.aspx.cs" Inherits="_Default" %&gt;
      &lt;asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent"&gt;
      &lt;/asp:Content&gt;
      &lt;asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent"&gt;
      &lt;h2&gt;Welcome to My Store!&lt;/h2&gt;
  
      &lt;table id="itempanel" runat="server"&gt;&lt;/table&gt;
      &lt;asp:Button ID="additem" Text="Add" OnClick="addElement" runat="server" /&gt;
  
      &lt;/asp:Content&gt;
  </code></pre>
  
  <p>Default.aspx.cs</p>
  
  <pre><code>public partial class _Default : System.Web.UI.Page
  {
  protected void Page_Load(object sender, EventArgs e)
  {
  
  }
  
  protected void addElement(object sender, EventArgs e)
  {
      HtmlTableRow tr=new HtmlTableRow();
      HtmlTableCell tc = new HtmlTableCell();
      DropDownList mylist = new DropDownList();
      ListItem myitem = new ListItem("Item1");
      mylist.Items.Add(myitem);
      myitem = new ListItem("Item2");
      mylist.Items.Add(myitem);
      myitem = new ListItem("Item3");
      mylist.Items.Add(myitem);
      tc.Controls.Add(mylist);
      tr.Cells.Add(tc);
      itempanel.Rows.Add(tr);
    }
  }
  </code></pre>