Reset Controls

02/06/2009 17:27

 protected void ResetButton1_Click(object sender, EventArgs e)
  {
  ResetFormControlValues(this);
  }

  private void ResetFormControlValues(Control parent)
  {
  foreach (Control c in parent.Controls)
  {
  if (c.Controls.Count > 0)
  {
  ResetFormControlValues(c);
  }
  else
  {
  switch (c.GetType().ToString())
  {
  case "System.Web.UI.WebControls.TextBox":
  ((TextBox)c).Text = "";
  break;
  case "System.Web.UI.WebControls.CheckBox":
  ((CheckBox)c).Checked = false;
  break;
  case "System.Web.UI.WebControls.RadioButton":
  ((RadioButton)c).Checked = false;
  break;

  }
  }
  }
  }
 

Contact

M. Jeyachandran @ M.Jayaramchandran 9840923422 jayaramchandran.m@gmail.com