John_Dong
John_Dong

Reputation: 49

Determine number of characters entered into textbox with C#

Hi I was wanting to display the number of characters entered into a textbox and I want it to update as I type how can I go about this?

Here is what I have:

int kk = textBox1.MaxLength;
int jj = //This is what I need to know.
string lol = jj.ToString() + "/" + kk.ToString();
label2.Text = lol;

Upvotes: 2

Views: 45733

Answers (4)

Mamdouh Emam
Mamdouh Emam

Reputation: 345

you can use the OnTextChanged event of the Textbox on the client side in Javascript and compute the increment from.

Upvotes: 0

Kishore Kumar
Kishore Kumar

Reputation: 12884

TextBoxobject.Text.Length will give you the length of textbox value.

Upvotes: 1

Stuart Golodetz
Stuart Golodetz

Reputation: 20656

The text of the text box will be a string, so it has a Length property, i.e.:

textBox1.Text.Length

Upvotes: 2

Jon Skeet
Jon Skeet

Reputation: 1504072

How about

int jj = textBox1.Text.Length;

Or am I missing something?

Upvotes: 18

Related Questions