≡ Menu




how to clear controls in asp.net c#

Use following code in you page. At Calling Statement send reference of page “this”. It Clears all text boxes and set all checkboxes on page to false

private void ClearControls(Control parent)
{
foreach (Control _ChildControl in parent.Controls)
{
if ((_ChildControl.Controls.Count > 0))
{
ClearControls(_ChildControl);
}
else
{
if (_ChildControl is TextBox)
{
((TextBox)_ChildControl).Text = string.Empty;
}
else
if (_ChildControl is CheckBox)
{
((CheckBox)_ChildControl).Checked = false;
}

}
}
}

{ 0 comments… add one }

Leave a Comment