I have many text box in an asp.net application, and after submitting their values i want to clear all fields when it loads again?
To clear all the input in an HTML form, use the <input> tag with the type attribute as reset.
The reset() method resets the values of all elements in a form (same as clicking the Reset button). Tip: Use the submit() method to submit the form.
To clear input values after form submit in React: Store the values of the input fields in state variables. Set the onSubmit prop on the form element. When the submit button is clicked, set the state variables to empty strings.
Once the OK button of the JavaScript Alert Message Box is clicked, the form fields (data) is cleared (reset) by redirecting to the same page using JavaScript window. location function.
you need to write and call similar function
after submit
public static void EmptyTextBoxes(Control parent)
{
foreach (Control c in parent.Controls) {
if (c.GetType() == typeof(TextBox))
{
((TextBox)(c)).Text = string.Empty;
}
}
}
reference
http://www.tek-tips.com/faqs.cfm?fid=6470
And this for clearing all controls in form like textbox, checkbox, radioButton
you can add different types you want..
private void ClearTextBoxes(Control control)
{
foreach (Control c in control.Controls)
{
if (c is TextBox)
{
((TextBox)c).Clear();
}
if (c.HasChildren)
{
ClearTextBoxes(c);
}
if (c is CheckBox)
{
((CheckBox)c).Checked = false;
}
if (c is RadioButton)
{
((RadioButton)c).Checked = false;
}
}
}
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