I have an asp.net
form
. In this form
I want to clear all the data what I entered in textbox
,dropdownlist
etc. So how can I do without going to each textbox and set the value.
like TextBox1.Text="";
etc. How can i clear all values of a form ?
Either
Use this function
private void ClearInputs(ControlCollection ctrls)
{
foreach (Control ctrl in ctrls)
{
if (ctrl is TextBox)
((TextBox)ctrl).Text = string.Empty;
else if (ctrl is DropDownList)
((DropDownList)ctrl).ClearSelection();
ClearInputs(ctrl.Controls);
}
}
and call it like
ClearInputs(Page.Controls);
or
Redirect to the same page
Response.Redirect(Request.Url.PathAndQuery, true);
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