Click here to Skip to main content
15,891,423 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 103.7K   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
Arun935358923-Oct-12 2:52
Arun935358923-Oct-12 2:52 

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.