65.9K
CodeProject is changing. Read more.
Home

How to clear a Multiple TextBox values in a single click in C# .NET

emptyStarIconemptyStarIconemptyStarIconemptyStarIconemptyStarIcon

0/5 (0 vote)

Sep 28, 2011

CPOL
viewsIcon

6094

We can better have an extension like: public static class ControlExtension { public static IList FindControlByName(this Control control) where T : Control { List controlsFound = new List(); controlsFound.AddRange(control.Controls.OfType()); ...

We can better have an extension like:
 public static class ControlExtension
  {
    public static IList<t> FindControlByName<t>(this Control control) where T : Control
    {
      List<t> controlsFound = new List<t>();

      controlsFound.AddRange(control.Controls.OfType<t>());
      foreach (Control c in control.Controls)
      {
        controlsFound.AddRange(FindControlByName<t>(c));
      }
      return controlsFound;
    }
  }
and perform:
this.FindControlByName<textbox>().ToList().ForEach(t => t.Clear());