Click here to Skip to main content
Click here to Skip to main content

Tagged as

Go to top

How to clear a Multiple TextBox values in a single click in C# .NET

, 26 Sep 2011
Rate this:
Please Sign up or sign in to vote.
Using this method, we can clear the text stored in a textbox easily.
protected void Button2_Click(object sender, EventArgs e)
{
    ClearInputs(Page.Controls);
}
void ClearInputs(ControlCollection ctrls)
{
    foreach (Control ctrl in ctrls)
    {
        if (ctrl is TextBox)
            ((TextBox)ctrl).Text = string.Empty;
        ClearInputs(ctrl.Controls);
    }
}

License

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

Share

About the Author

CS1401
Software Developer (Junior) CS1401
India India


Any fool can write code that a computer can understand. Good programmers write code that humans can understand.


Comments and Discussions

 
GeneralMy vote of 4 PinmemberFlash2009-MX29-Nov-12 9:00 
GeneralMy vote of 5 PinmemberMember 935358923-Oct-12 2:52 
GeneralRe: ya its real. Thanks for your code.;) PinmemberCS140120-Sep-11 19:57 
GeneralRe: I think you are right....I guess, I took it a wrong way..:) Pinmembersachinsharmaa10220-Sep-11 2:24 
GeneralReason for my vote of 5 This might be helpful in my future r... PinmemberVarun Sareen18-Nov-11 0:47 
GeneralReason for my vote of 3 Reason for my vote of 3 Nice. Pinmembermaheshsanika15-Nov-11 21:21 
GeneralReason for my vote of 3 Nice. Pinmembermaheshsanika15-Nov-11 21:20 
GeneralAlthough nothing new, I like this one and have done similar ... PinmemberMarcus Kramer27-Oct-11 4:38 
Although nothing new, I like this one and have done similar things in the past. +4. My issue with this is that if there are that many text controls on a page that would warrant this approach to clear them all, then the page is perhaps too large. As well, in my experience, text boxes on a form are usually set to a default state and that default state on a properly designed form would contain values other than string.empty.
Generalcorrect me if i'm wrong, but this will have no effect on nes... PinmemberEngleA4-Oct-11 9:13 
GeneralReason for my vote of 2 Old hat PinmemberJohn Kouw26-Sep-11 22:12 
GeneralReason for my vote of 5 ah ah ah :)! I laughed because this ... Pinmemberjonanirina26-Sep-11 21:14 
GeneralUse databinding, Luke! 8) PinmemberAlexander Voronin26-Sep-11 20:43 
GeneralReason for my vote of 3 nice Pinmembervipin bakaya26-Sep-11 18:28 
GeneralReason for my vote of 3 What is the purpose of Calling Clear... PinmemberPrabhu_R24-Sep-11 4:05 
GeneralRe: mr.Prabhu_R did u check my code before write this comment? D... PinmemberCS140125-Sep-11 18:28 
GeneralReason for my vote of 4 Seen many variations of this... almo... PinmemberBrianBissell20-Sep-11 2:47 
GeneralWhat about the situation where we need to clear some of the ... Pinmemberoorja20-Sep-11 0:20 
GeneralRe: if you want to clear the specific text box means u will writ... PinmemberCS140120-Sep-11 0:56 
GeneralRe: Check it out here: <b><a href="http://www.vbforfree.com/?p=2... Pinmember98z2820-Sep-11 9:25 
GeneralReason for my vote of 3 can be done more easily...i apprecia... Pinmembersachinsharmaa10219-Sep-11 21:56 
GeneralRe: This is the easiest way in my experience. In web application... PinmemberCS140119-Sep-11 23:42 

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 | Mobile
Web01 | 2.8.140926.1 | Last Updated 27 Sep 2011
Article Copyright 2011 by CS1401
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid