private void ClearTextBox() { foreach (var control in pnlDetail.Controls) { if (!(control is TextBox)) continue; var txtBox = (TextBox)control; txtBox.Text = String.Empty; } }