Click here to Skip to main content
15,910,886 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
Hi
i have above 100 different input field in one form. After inserting all the input data into database . i should clear all the input fields for that i am assigning null value for each input field i think it lengthy process assigning null value to 100 field . is there any simple process for clearing all the input fields ?
Posted
Comments
MCY 28-Jan-11 7:38am    
are input fields "html input" or asp textbox?
#realJSOP 28-Jan-11 10:39am    
You don't have to mark ALL of the answers as "the" answer.

C#
foreach (Control item in this.Controls)
{
    if (item is textBox)
    {
        (item as TextBox).Text = "";
    }
}


C#
private void ClearTextBoxes(Control parent)
{
    if (parent is TextBox)
    {
        (item as TextBox).Text = "";
    }
    else
    {
        if (parent.Controls.Count > 0)
        {
            foreach (Control item in parent.Controls)
            {
                ClearTextBoxes(parent);
            }
        }
    }
}


Call that method like so:

C#
foreach (Control item in this.Controls)
{
    ClearTextBoxes(item);
}
 
Share this answer
 
v3
Comments
srinivasvempa 28-Jan-11 7:28am    
sorry Not working i need more code anyway thanx
#realJSOP 28-Jan-11 7:47am    
You "need more code"? Be a programmer fer christ's sake. I modified my answer to give you "more code". It may need to be tweaked, but you should get the idea...
soni uma 28-Jan-11 7:50am    
good answer dude...
Have a look at this Tip/Trick: Simple and easy way to clear all the input fields in the form.[^]

There are 3 ways mentioned in it that can be used to do the same. Pick the one you like.
 
Share this answer
 
You can use javascript . I am not clear but form.clear() is use full. Search on that.
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900