HTML has an input button type to reset all fields in a form to their initial state in one step: .
Is there a similar
using the manual approach of String.Empty
for each and every Textbox or any other field will be cumbersome, also by using Response.Redirect();
it will be difficult to show any confirmation message or same. So, on reading so many blogs i have found a reliable approach so far:
Public void reset(Control control)
{
foreach (Control x in control.Controls)
{
if (x is TextBox)
{
(x as TextBox).Text = String.Empty;
}
else if (x is DropDownList)
{
(x as DropDownList).SelectedIndex = 0;
}
.
.
reset(x);
}
}
use this code as reset(this);
in your page wherever you want to reset or clear the values. At end of the if
conditions do not forget to use the function recursively using the same