Clearing a TextBox in ASP.NET

The best way to do this is

textbox.text = string.Empty;

Also remember that string type is immutable!


It makes no difference - do what is most readable for you and your colleagues.

Many prefer to use string.Empty.


  1. The performance difference between the two options will be too small to measure, most likely.
  2. TextBox.Text = String.Empty; is a lot more readable. It clearly states what you're trying to do: "set the text property of this text box to an empty string".

I recommend you go with the assignment, as it is both faster, and much more clear.

Tags:

C#

Asp.Net