如何在C#中的标签中显示剩余的文本框字符? [英] How to display remaining textbox characters in a label in C#?

查看:152
本文介绍了如何在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

这篇关于如何在C#中的标签中显示剩余的文本框字符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆