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.

Comments

Popular posts from this blog

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

Why Dispose() is preferred than Finalize() for Un-Managed Resources in .NET?

How to apply watermark to the textbox and dropdownlist?