Topic: CONTROL ForEach to clear value
Share/Save/Bookmark
CONTROL ForEach to clear value
 
void ClearTextBoxes()
{
      foreach(object ctrl in Page.Controls)
      {
            if ( ctrl is System.Web.UI.HtmlControls.HtmlForm )
            {
                  System.Web.UI.HtmlControls.HtmlForm form =
                              (System.Web.UI.HtmlControls.HtmlForm)ctrl;
                  foreach(object subctrl in form.Controls)
                  {
                        if (subctrl is System.Web.UI.WebControls.TextBox)
                        {
                              TextBox textctrl = (TextBox)subctrl;
                              textctrl.Text = "";
                        }
                  }
            }
      }
}