How to Clear the Textbox Text using C#?

This is one of the common requirement we get in our projects.Text box has a wonderful method called "Clear".This method is used to clear the text in the Text box.I have given a simple example to explain this .I have implemenetd a common method to clear the Text of few Controls .One of that is Textbox.


void ClearInputs(ControlCollection ctrls)
{
    foreach (Control ctrl in ctrls)
    {
        if (ctrl is TextBox)
            ((TextBox)ctrl).Text = string.Empty;
        ClearInputs(ctrl.Controls);
    }
}
 
You can call this  method where ever you want to clear the Text from the Textbox.
For more information please click this link
TextBox 
 
 
Hope this would help the beginners. 
Cheers.

Popular posts from this blog

Exporting to excel from a custom class object using C#.NET

How to hide bootStrap popover when user click(s) outside the popover?

Get the Clicked Cell Value and Column Name of GridView in ASP.NET