Click here to Skip to main content
11,483,983 members (66,157 online)
Click here to Skip to main content

Tagged as

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

, 26 Sep 2011 CPOL 58.4K 15
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

 
QuestionHow to add an exempt button Pin
Daniel Ian M. Del Rosario9-Mar-15 22:56
memberDaniel Ian M. Del Rosario9-Mar-15 22:56 
GeneralMy vote of 4 Pin
Flash2009-MX29-Nov-12 10:00
memberFlash2009-MX29-Nov-12 10:00 
GeneralMy vote of 5 Pin
Member 935358923-Oct-12 3:52
memberMember 935358923-Oct-12 3:52 
GeneralRe: ya its real. Thanks for your code.;) Pin
CS140120-Sep-11 20:57
memberCS140120-Sep-11 20:57 
GeneralRe: I think you are right....I guess, I took it a wrong way..:) Pin
sachinsharmaa10220-Sep-11 3:24
membersachinsharmaa10220-Sep-11 3:24 
GeneralReason for my vote of 5 This might be helpful in my future r... Pin
Varun Sareen18-Nov-11 1:47
memberVarun Sareen18-Nov-11 1:47 
GeneralReason for my vote of 3 Reason for my vote of 3 Nice. Pin
maheshsanika15-Nov-11 22:21
membermaheshsanika15-Nov-11 22:21 
GeneralReason for my vote of 3 Nice. Pin
maheshsanika15-Nov-11 22:20
membermaheshsanika15-Nov-11 22:20 
GeneralAlthough nothing new, I like this one and have done similar ... Pin
Marcus Kramer27-Oct-11 5:38
memberMarcus Kramer27-Oct-11 5:38 
Generalcorrect me if i'm wrong, but this will have no effect on nes... Pin
EngleA4-Oct-11 10:13
memberEngleA4-Oct-11 10:13 
correct me if i'm wrong, but this will have no effect on nested textboxes, like those inside a panel...
GeneralReason for my vote of 2 Old hat Pin
John Kouw26-Sep-11 23:12
memberJohn Kouw26-Sep-11 23:12 
GeneralReason for my vote of 5 ah ah ah :)! I laughed because this ... Pin
jonanirina26-Sep-11 22:14
memberjonanirina26-Sep-11 22:14 
GeneralUse databinding, Luke! 8) Pin
Alexander Voronin26-Sep-11 21:43
memberAlexander Voronin26-Sep-11 21:43 
GeneralReason for my vote of 3 nice Pin
vipin bakaya26-Sep-11 19:28
membervipin bakaya26-Sep-11 19:28 
GeneralReason for my vote of 3 What is the purpose of Calling Clear... Pin
Prabhu_R24-Sep-11 5:05
memberPrabhu_R24-Sep-11 5:05 
GeneralRe: mr.Prabhu_R did u check my code before write this comment? D... Pin
CS140125-Sep-11 19:28
memberCS140125-Sep-11 19:28 
GeneralReason for my vote of 4 Seen many variations of this... almo... Pin
BrianBissell20-Sep-11 3:47
memberBrianBissell20-Sep-11 3:47 
GeneralWhat about the situation where we need to clear some of the ... Pin
oorja20-Sep-11 1:20
memberoorja20-Sep-11 1:20 
GeneralRe: if you want to clear the specific text box means u will writ... Pin
CS140120-Sep-11 1:56
memberCS140120-Sep-11 1:56 
GeneralRe: Check it out here: <b><a href="http://www.vbforfree.com/?p=2... Pin
98z2820-Sep-11 10:25
member98z2820-Sep-11 10:25 
GeneralReason for my vote of 3 can be done more easily...i apprecia... Pin
sachinsharmaa10219-Sep-11 22:56
membersachinsharmaa10219-Sep-11 22:56 
GeneralRe: This is the easiest way in my experience. In web application... Pin
CS140120-Sep-11 0:42
memberCS140120-Sep-11 0: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 | Terms of Use | Mobile
Web04 | 2.8.150520.1 | Last Updated 27 Sep 2011
Article Copyright 2011 by CS1401
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid