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
Hirendra SisodiyaPosted Apr 7, 2010, 2:02 AM
you can use 'length' property of textbox.text..simple....
thankyou
VasanthPosted Apr 6, 2010, 3:15 AM
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.
Jaish MathewsPosted Apr 6, 2010, 3:15 AM
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);");
}
Deepak AroraPosted Apr 6, 2010, 3:12 AM
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 AroraPosted Apr 6, 2010, 3:11 AM
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 AroraPosted Apr 6, 2010, 3:05 AM
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
ajay rajuPosted Apr 6, 2010, 2:08 AM
mainly i used web. (also give a code for windows)
ajay rajuPosted Apr 6, 2010, 2:06 AM
It is not working.
Posted Apr 5, 2010, 1:00 PM
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
Jaish MathewsPosted Apr 5, 2010, 12:42 PM