Click here to Skip to main content
15,867,686 members
Articles / Programming Languages / C# 4.0
Tip/Trick

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

Rate me:
Please Sign up or sign in to vote.
4.22/5 (23 votes)
26 Sep 2011CPOL 102.4K   15   23
Using this method, we can clear the text stored in a textbox easily.
C#
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)


Written By
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 5 Pin
hope_amal12-Sep-15 11:07
hope_amal12-Sep-15 11:07 
QuestionHow to add an exempt button Pin
Daniel Ian M. Del Rosario9-Mar-15 21:56
Daniel Ian M. Del Rosario9-Mar-15 21:56 
GeneralMy vote of 4 Pin
Flash2009-MX29-Nov-12 9:00
Flash2009-MX29-Nov-12 9:00 
interesting
GeneralMy vote of 5 Pin
Arun935358923-Oct-12 2:52
Arun935358923-Oct-12 2:52 
GeneralRe: ya its real. Thanks for your code.;) Pin
CS140120-Sep-11 19:57
CS140120-Sep-11 19:57 
GeneralRe: I think you are right....I guess, I took it a wrong way..:) Pin
Sachin_Sharma(10)20-Sep-11 2:24
Sachin_Sharma(10)20-Sep-11 2:24 
GeneralReason for my vote of 5 This might be helpful in my future r... Pin
Varun Sareen18-Nov-11 0:47
Varun Sareen18-Nov-11 0:47 
GeneralReason for my vote of 3 Reason for my vote of 3 Nice. Pin
Mahesh Sanika15-Nov-11 21:21
Mahesh Sanika15-Nov-11 21:21 
GeneralReason for my vote of 3 Nice. Pin
Mahesh Sanika15-Nov-11 21:20
Mahesh Sanika15-Nov-11 21:20 
GeneralAlthough nothing new, I like this one and have done similar ... Pin
fjdiewornncalwe27-Oct-11 4:38
professionalfjdiewornncalwe27-Oct-11 4:38 
Generalcorrect me if i'm wrong, but this will have no effect on nes... Pin
EngleA4-Oct-11 9:13
EngleA4-Oct-11 9:13 
GeneralReason for my vote of 2 Old hat Pin
John Kouw26-Sep-11 22:12
John Kouw26-Sep-11 22:12 
GeneralReason for my vote of 5 ah ah ah :)! I laughed because this ... Pin
CiKamaNdeela26-Sep-11 21:14
CiKamaNdeela26-Sep-11 21:14 
GeneralUse databinding, Luke! 8) Pin
Alexander Voronin26-Sep-11 20:43
Alexander Voronin26-Sep-11 20:43 
GeneralReason for my vote of 3 nice Pin
vipin bakaya26-Sep-11 18:28
vipin bakaya26-Sep-11 18:28 
GeneralReason for my vote of 3 What is the purpose of Calling Clear... Pin
rprabhuit24-Sep-11 4:05
rprabhuit24-Sep-11 4:05 
GeneralRe: mr.Prabhu_R did u check my code before write this comment? D... Pin
CS140125-Sep-11 18:28
CS140125-Sep-11 18:28 
GeneralReason for my vote of 4 Seen many variations of this... almo... Pin
BrianBissell20-Sep-11 2:47
BrianBissell20-Sep-11 2:47 
GeneralWhat about the situation where we need to clear some of the ... Pin
oorja20-Sep-11 0:20
oorja20-Sep-11 0:20 
GeneralRe: if you want to clear the specific text box means u will writ... Pin
CS140120-Sep-11 0:56
CS140120-Sep-11 0:56 
GeneralRe: Check it out here: <b><a href="http://www.vbforfree.com/?p=2... Pin
98z2820-Sep-11 9:25
98z2820-Sep-11 9:25 
GeneralReason for my vote of 3 can be done more easily...i apprecia... Pin
Sachin_Sharma(10)19-Sep-11 21:56
Sachin_Sharma(10)19-Sep-11 21:56 
GeneralRe: This is the easiest way in my experience. In web application... Pin
CS140119-Sep-11 23:42
CS140119-Sep-11 23:42 

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

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