hi!
in my textbox control i give maxlength=150. and bottom of the control i take label. when user enter the characters into textbox, the label shows the values decrement by 1 upto 0. at the same time user erase the characters this time increment by 1 upto 150.
please give a code to do this.
thanks
Loading

Jaish MathewsRank #225 · 11K reputationPosted Apr 5, 2010, 8:42 AM EDT
Posted Apr 5, 2010, 9:00 AM EDT
It's pretty easy.i assume u know all the basics....first pull up a text box(say textbox1) from toolbox and set it's maximum length to 150 in it's properties.next pull up a label(say label1) from toolbox.....In the textchnaged event of textbox(i.e)double click the textbox and write the following line
label1.Text = textbox1.Text.Length.ToString();
Hope your requirement is satisfied..
Any doubts feel free to ask..
----------------------------------------------------------------------------------------------------------------
If someway my answer helped u don't forget to mark it as accepted answer......Thank u
ajay rajuRank #4,639 · 333 reputationPosted Apr 5, 2010, 10:06 PM EDT
It is not working.
ajay rajuRank #4,639 · 333 reputationPosted Apr 5, 2010, 10:08 PM EDT
mainly i used web. (also give a code for windows)
Deepak Arora10 reputationPosted Apr 5, 2010, 11:05 PM EDT
hi ajay,
private void textBox1_TextChanged(object sender, EventArgs e)
{
label1.Text = Convert.ToInt32((textBox1.MaxLength) - (textBox1.Text.Length)).ToString();
}
If answer is helpful plz mark it as accepted answer......Thank u
Deepak Arora10 reputationPosted Apr 5, 2010, 11:11 PM EDT
hi ajay,
private void textBox1_TextChanged(object sender, EventArgs e)
{
label1.Text = Convert.ToInt32((textBox1.MaxLength) - (textBox1.Text.Length)).ToString();
}
If answer is helpful plz mark it as accepted answer......Thank u
Deepak Arora10 reputationPosted Apr 5, 2010, 11:12 PM EDT
hi ajay,
private void textBox1_TextChanged(object sender, EventArgs e)
{
label1.Text = Convert.ToInt32((textBox1.MaxLength) - (textBox1.Text.Length)).ToString();
}
If answer is helpful plz mark it as accepted answer......Thank u
Jaish MathewsRank #225 · 11K reputationPosted Apr 5, 2010, 11:15 PM EDT
Should be used JavaScript. Here small sample. But need to handle additional things, if needed ie. any special character handlings.
aspx
JavaScript
function HandleKeyUp(ctlr)
{
var label = $get("statusLabel");
var length = ctlr.value.length
label.innerText = "You reached " + length + " characters";
}
CodeBehind
if (!IsPostBack)
{
TextBox1.Attributes.Add("onkeyup", "HandleKeyUp(this);");
}
VasanthRank #1,486 · 1.1K reputationPosted Apr 5, 2010, 11:15 PM EDT
Please add below attributes for the textbox event ,
[ Javascript ]
function CheckLength(txt,maxLen)
{
try
{
if(txt!= null)
{
var iLength = txt.value.length
if (iLength <= maxLen) //Check the Limit.
{
//Display the remaining characters
document.getElementById('
}
else
{
txt.value = txt.value.substring(0, maxLen);
return false;
}
}
}
catch(e)
{
return false;
}
}
Please mark as answer if its help out.
Hirendra SisodiyaRank #258 · 9.8K reputationPosted Apr 6, 2010, 10:02 PM EDT
you can use 'length' property of textbox.text..simple....
thankyou