如何在C#中的标签中显示剩余的文本框字符?
我不确定我最后一个位是否正确?我将文本框的最大长度更改为140.我似乎不能使用 TextLength
。请帮助?!我到目前为止:
I'm not sure if I have the last bit right? I changed the max length of the textbox to 140. I can't seem to use TextLength
. Help please?! I have this so far:
protected void textBox_TextChanged(object sender, EventArgs e)
{
characterCountLabel.Text = textBox.MaxLength - textBox.TextLength;
}
characterCountLabel.Text
是字符串格式。所以你可能想要转换它之前你设置它的值,像这样:
characterCountLabel.Text
is in string format. So you might want to convert it before you set its value like this:
protected void textBox_TextChanged(object sender, EventArgs e)
{
characterCountLabel.Text = (textBox.MaxLength - textBox.Text.Length).ToString();
}
我想你正在尝试显示用户可以输入到文本框?我建议你可以设置限制为常数,如下:
I think you are trying to display the remaining characters the user can input to your text box? I suggest that you can set the limit as constant like this:
protected void textBox_TextChanged(object sender, EventArgs e)
{
characterCountLabel.Text = (140 - textBox.Text.Length).ToString(); // in here 140 is your limit
}
如果您使用ASP.NET C#。不要限制自己使用javascript 喜欢在此链接
If you are using ASP.NET in C#. Don't limit yourself from using javascript like in this link