# How To Clear All Textboxes in ASP.NET

As per the Wikipedia

ASP.NET is an open-source, server-side web-application framework designed for web development to produce dynamic web pages. It was developed by Microsoft to allow programmers to build dynamic web sites, applications and services.

In this article, I will show you how to clear all the textbox present on the page.
Check out the following code snippet and call the following method in Page_Load.

private void ClearAllTextboxes()
{
Control myForm = Page.FindControl("Form1");

foreach (Control ctl in myForm.Controls)
{
if (ctl.GetType().ToString().Equals("System.Web.UI.WebControls.TextBox"))
{
((TextBox)ctl).Text = "";
}
}
}



This will clear EVERYTHING from the textboxes - even if you had them pre-populated with data

Reactions