Click here to Skip to main content
13,860,642 members
Click here to Skip to main content
Add your own
alternative version

Tagged as


2 bookmarked
Posted 22 Sep 2011
Licenced CPOL

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

, 22 Sep 2011
Rate this:
Please Sign up or sign in to vote.
A generic text clear method for those ASP.NET controls which implement the ITextControl interface:private void Clear(ControlCollection controlCollection) where T : ITextControl{ if (controlCollection == null) return; ...

A generic text clear method for those ASP.NET controls which implement the ITextControl interface:

private void Clear<T>(ControlCollection controlCollection)
    where T : ITextControl
    if (controlCollection == null) return;
    controlCollection.Cast<Control>().ToList().ForEach(control =>
        var textCollection = control.Controls.OfType<T>();
        if (textCollection.Count() > 0)
            textCollection.ToList<T>().ForEach(textBox => textBox.Text = string.Empty);

Usage: a button click from an ASP.NET page:

protected void btnClear_Click(object sender, EventArgs e)


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


About the Author

You may also be interested in...

Comments and Discussions

GeneralThis is more generic way to handle controls in a page. Pin
Mukund Thakker26-Sep-11 19:52
professionalMukund Thakker26-Sep-11 19:52 
GeneralRe: Thanks Mukund :) Pin
Mohammad A Rahman26-Sep-11 19:54
memberMohammad A Rahman26-Sep-11 19:54 

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.

Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web03 | 2.8.190214.1 | Last Updated 22 Sep 2011
Article Copyright 2011 by Mohammad A Rahman
Everything else Copyright © CodeProject, 1999-2019
Layout: fixed | fluid