Properties in code built table in asp.net
<p>I'm doing an exercise on asp.net using code generated tables with a very simple code:</p>

<pre><code>protected void btnAceptar_Click(object sender, EventArgs e)
    {
        tblGenerar.Controls.Clear();            

        for(int i = 0; i &lt; Convert.ToInt32(txtRows.Text);i++)
        {
            TableRow rowNew = new TableRow();
            tblGenerar.Rows.Add(rowNew);

            for (int j = 0; j &lt; Convert.ToInt32(txtCols.Text);j++ )
            {
                TableCell cellNew = new TableCell();
                rowNew.Cells.Add(cellNew);
                cellNew.Text = txtTexto.Text;

                if (chkMargen.Checked == true)
                {
                    cellNew.BorderStyle = BorderStyle.Inset;
                    cellNew.BorderWidth = 1;
                }
            }
        }
    }
</code></pre>

<p>The first time I choose to create border on the table, it works, but next time I choose to generate the table without the borders, the borders from last generated table are still there. Additional cells appears with no borders.</p>

<p>Why does this happen if I'm using Controls.Clear() and how can I solve it?<br>
Thanks.</p>
