Determine number of characters entered into textbo

2019-03-01 14:20发布

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;

4条回答
啃猪蹄的小仙女
2楼-- · 2019-03-01 14:29

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

查看更多
女痞
3楼-- · 2019-03-01 14:37

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

查看更多
劳资没心,怎么记你
4楼-- · 2019-03-01 14:39

How about

int jj = textBox1.Text.Length;

Or am I missing something?

查看更多
我欲成王,谁敢阻挡
5楼-- · 2019-03-01 14:53

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

textBox1.Text.Length
查看更多
登录 后发表回答