title: How can I dynamically clear all controls in a user control?
body: <p>Is it possible to dynamically (and generically) clear the state of all of a user control's child controls? (e.g., all of its TextBoxes, DropDrownLists, RadioButtons, DataGrids, Repeaters, etc -- basically anything that has ViewState)</p>
  
  <p>I'm trying to avoid doing something like this:</p>
  
  <pre><code>foreach (Control c in myUserControl.Controls)
  {
      if (c is TextBox)
      {
          TextBox tb = (TextBox)c;
          tb.Text = "";
      }
      else if (c is DropDownList)
      {
          DropDownList ddl = (DropDownList)c;
          ddl.SelectedIndex = -1;
      }
      else if (c is DataGrid)
      {
          DataGrid dg = (DataGrid)c;
          dg.Controls.Clear();
      }
  
      // etc.
  
  }
  </code></pre>
  
  <p>I'm looking for something like this:</p>
  
  <pre><code>foreach (Control c in myUserControl.Controls)
      c.Clear();
  </code></pre>
  
  <p>...but obviously that doesn't exist. Is there any easy way to accomplish this dynamically/generically?</p>