Whats the easiest way to clear an asp.net form at runtime using c#.
Thanks Sp
I assume you want to clear input boxes, dropdowns etc. This can be done the following way in code to recursivly clear all data.
foreach( var control in this.Controls )
{
ClearControl( control );
}
and the recursive function
private void ClearControl( Control control )
{
var textbox = control as TextBox;
if (textbox != null)
textbox.Text = string.Empty;
var dropDownList = control as DropDownList;
if (dropDownList != null)
dropDownList.SelectedIndex = 0;
// handle any other control //
foreach( Control childControl in control.Controls )
{
ClearControl( childControl );
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With