title: Removing dynamically created controls
body: <p>I am attempting to remove dynamically created controls in C# 2008 asp.net</p>
  
  <p>The controls are created here:</p>
  
  <pre><code>        int i;
          for (i = 0; i &lt; myCount; i += 1)
          {
              TextBox txtAuto = new TextBox();
              TextBox txtModel = new TextBox();
              TextBox txtMiles = new TextBox();
              TextBox txtVINumber = new TextBox();
              TextBox txtPlateNumber = new TextBox();
  
              txtAuto.ID = "txtVehAuto" + i.ToString();
              txtModel.ID = "txtVehModel" + i.ToString();
              txtMiles.ID = "txtVehMilage" + i.ToString();
              txtVINumber.ID = "txtVehVINumber" + i.ToString();
              txtPlateNumber.ID = "txtVehPlate" + i.ToString();
  
              phAuto.Controls.Add(txtAuto);
              phModel.Controls.Add(txtModel);
              phMiles.Controls.Add(txtMiles);
              phVINumber.Controls.Add(txtVINumber);
              phPlateNumber.Controls.Add(txtPlateNumber);
  
              dyntxtAuto[i] = txtAuto;
              dyntxtModel[i] = txtModel;
              dyntxtMiles[i] = txtMiles;
              dyntxtVINumber[i] = txtVINumber;
              dyntxtPlateNumber[i] = txtPlateNumber;
  
              LiteralControl literalBreak = new LiteralControl("&lt;br /&gt;");
  
              phAuto.Controls.Add(literalBreak);
              phModel.Controls.Add(literalBreak);
              phMiles.Controls.Add(literalBreak);
              phVINumber.Controls.Add(literalBreak);
              phPlateNumber.Controls.Add(literalBreak);
          }
      }
  </code></pre>
  
  <p>How can I remove the controls? 
  The user will click "submit" at which point the user entered data will be written to the db. The page will retrun back to itself (with blank fields). I want to remove the dynamic controls after the data has been written to the db. Remove meaning delete, not hide. I tried to set ViewState to false, but it doesn't help.</p>