Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Clear all fields after submit

Tags:

c#

asp.net

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?

like image 226
Sheery Avatar asked Mar 01 '10 12:03

Sheery


People also ask

How do you clear all fields in form?

To clear all the input in an HTML form, use the <input> tag with the type attribute as reset.

How do you clear data after submitting HTML?

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.

How do you clear fields after form submit react?

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.

How do you clear fields after form submit in asp net?

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.


2 Answers

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

like image 178
Asad Avatar answered Sep 21 '22 23:09

Asad


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;
            }
        }
    }
like image 44
Chandan Pasunoori Avatar answered Sep 17 '22 23:09

Chandan Pasunoori