private void ClearEditCustomerForm()
{
//Empty out text boxes
var textBoxes = new List<Control>();
FindControlsOfType(this.phrEditCustomer, typeof(TextBox), textBoxes);
foreach (TextBox textBox in textBoxes)
textBox.Text = "";
// Dropdowns
var dropdowns = new List<Control>();
FindControlsOfType(this.phrEditCustomer, typeof(DropDownList), dropdowns);
foreach (DropDownList drop in dropdowns)
{
drop.SelectedValue = "0";
}
//Clear validators
var validators = new List<Control>();
FindControlsOfType(this.phrEditCustomer, typeof(BaseValidator), validators);
foreach (BaseValidator validator in validators)
validator.IsValid = true;
}
static public void FindControlsOfType(Control root, Type controlType, List<Control> list)
{
if (root.GetType() == controlType || root.GetType().IsSubclassOf(controlType))
{
list.Add(root);
}
//Skip input controls
if (!root.HasControls())
return;
foreach (Control control in root.Controls)
{
FindControlsOfType(control, controlType, list);
}
}
No comments:
Post a Comment