Use Controls.Remove or Controls.RemoveAt parent ControlCollection .
For example, if you want to remove all text fields from the page at the top of the page:
var allTextBoxes = Page.Controls.OfType<TextBox>().ToList(); foreach(TextBox txt in allTextBoxes) Page.Controls.Remove(txt);
(note that you need to add using System.Linq for Enumerable.OfType )
or if you want to remove the TextBox with the given ID:
TextBox textBox1 = (TextBox)Page.FindControl("TextBox1");
If you just want to hide it (and completely remove it from the client), you can also make it invisible:
textBox1.Visible = false;
Tim schmelter
source share