Click here to Skip to main content
15,443,631 members
Articles / Programming Languages / C# 4.0
Posted 15 Sep 2011

Tagged as


15 bookmarked

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
Using this method, we can clear the text stored in a textbox easily.
protected void Button2_Click(object sender, EventArgs e)
void ClearInputs(ControlCollection ctrls)
    foreach (Control ctrl in ctrls)
        if (ctrl is TextBox)
            ((TextBox)ctrl).Text = string.Empty;


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
Memberhope_amal12-Sep-15 11:07 
QuestionHow to add an exempt button Pin
Daniel Ian M. Del Rosario9-Mar-15 21:56
MemberDaniel Ian M. Del Rosario9-Mar-15 21:56 
GeneralMy vote of 4 Pin
Flash2009-MX29-Nov-12 9:00
MemberFlash2009-MX29-Nov-12 9:00 
GeneralMy vote of 5 Pin
Arun935358923-Oct-12 2:52
MemberArun935358923-Oct-12 2:52 
GeneralRe: ya its real. Thanks for your code.;) Pin
CS140120-Sep-11 19:57
MemberCS140120-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
MemberSachin_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
MemberVarun 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
MemberMahesh Sanika15-Nov-11 21:21 
GeneralReason for my vote of 3 Nice. Pin
Mahesh Sanika15-Nov-11 21:20
MemberMahesh 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
MemberEngleA4-Oct-11 9:13 
GeneralReason for my vote of 2 Old hat Pin
John Kouw26-Sep-11 22:12
MemberJohn Kouw26-Sep-11 22:12 
GeneralReason for my vote of 5 ah ah ah :)! I laughed because this ... Pin
CiKamaNdeela26-Sep-11 21:14
MemberCiKamaNdeela26-Sep-11 21:14 
GeneralUse databinding, Luke! 8) Pin
Alexander Voronin26-Sep-11 20:43
MemberAlexander Voronin26-Sep-11 20:43 
GeneralReason for my vote of 3 nice Pin
vipin bakaya26-Sep-11 18:28
Membervipin bakaya26-Sep-11 18:28 
GeneralReason for my vote of 3 What is the purpose of Calling Clear... Pin
rprabhuit24-Sep-11 4:05
Memberrprabhuit24-Sep-11 4:05 
GeneralRe: mr.Prabhu_R did u check my code before write this comment? D... Pin
CS140125-Sep-11 18:28
MemberCS140125-Sep-11 18:28 
GeneralReason for my vote of 4 Seen many variations of this... almo... Pin
BrianBissell20-Sep-11 2:47
MemberBrianBissell20-Sep-11 2:47 
GeneralWhat about the situation where we need to clear some of the ... Pin
oorja20-Sep-11 0:20
Memberoorja20-Sep-11 0:20 
GeneralRe: if you want to clear the specific text box means u will writ... Pin
CS140120-Sep-11 0:56
MemberCS140120-Sep-11 0:56 
GeneralRe: Check it out here: <b><a href=" Pin
98z2820-Sep-11 9:25
Member98z2820-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
MemberSachin_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
MemberCS140119-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.