Friday, September 24, 2010

Clear all values of textbox and checkbox from a particular asp.net page

Make the asp.net controls clear


If you want to clear the asp.net controls like textbox and textbox.

This function clears whole occurence of the the defined controls.

Just past the Varaible parent as 'this' , which will clear the whole controls from that particular page which are defined in this function.



public 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;

}

}

  }

  }

No comments:

Post a Comment