Click here to Skip to main content
11,567,926 members (47,758 online)
Click here to Skip to main content

Tagged as

Simple and easy way to clear all the input fields in the form.

, 26 Feb 2010 CPOL 4.3K 3
Rate this:
Please Sign up or sign in to vote.
This is an easy way to clear all input fields in the form.

ALTERNATIVE #1: via Server side Codebehind

Something like...

private void ResetFormControlValues(Control parent)
    {
        foreach (Control c in parent.Controls)
        {
            if (c.Controls.Count > 0)
            {
                ResetFormControlValues(c);
            }
            else
            {
                switch(c.GetType().ToString())
                {
                    case "System.Web.UI.WebControls.TextBox":
                        ((TextBox)c).Text = "";
                        break;
                    case "System.Web.UI.WebControls.CheckBox":
                        ((CheckBox)c).Checked = false;
                        break;
                    case "System.Web.UI.WebControls.RadioButton":
                        ((RadioButton)c).Checked = false;
                        break;
                  
                }               
            }
        }
    }

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Sandeep Mewara
Software Developer (Senior)
India India
Current location: Bangalore, India.

You may also be interested in...

Comments and Discussions

 
GeneralMy vote of 5 Pin
Ammar45562574-Oct-13 1:02
memberAmmar45562574-Oct-13 1:02 
QuestionMessage Automatically Removed Pin
15-Jan-13 4:34
memberbEGI2315-Jan-13 4:34 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.150624.2 | Last Updated 27 Feb 2010
Article Copyright 2010 by Sandeep Mewara
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid