Clearing TextBox in ASP.NET

I have a webpage where there is a text box with some default value.

I need to clear a value from a text box. I have 2 options

1. textbox.text="";
2. textbox.text.remove(0,length);

Here I would like to know which one I should use. This affects page performance because there are a lot of text fields on the page.

thanks

+5
source share
6 answers

The best way to do this is:

textbox.text = string.Empty;

Also remember that the string type is immutable!

+20
source

It doesn’t matter - do what is most readable to you and your colleagues.

Many prefer to use string.Empty.

+7
source
  • , , .
  • TextBox.Text = String.Empty; . , : " ".

, .

+2

, javascript, int ? , .

jQuery , , onClick, ClientId :

$('#ctl00_TextBox').click(function() { $('#ctl00_TextBox').val('');

, , :

yourTextBox.Text = String.Empty;
+1
textbox.text="";

 foreach (var item in Page.Controls)
    {
        if (item is TextBox)
        {
            ((TextBox)item).Text = "";
        }
    }
+1

/ ,

textbox.text = "";

, , ( .Remove)

-

textbox.text = String.Empty;

:, -, String.Empty , , "" String.

, , ! , ...

0

All Articles