MultiLine TextBox MaxLength Problem in asp.net
If Textbox style is set to multiline, Control will not validate for maxlength value set in property.
Multiple code has to be placed to handle this problem.
1.Use JavaScript to validate on each keystroke
add this to HTML tag of textbox
onKeyPress="return ValidateMultiLineTextboxMaxLength(this,250);"
JS for above Call
function ValidateMultiLineTextboxMaxLength(txtbox,MaxLen)
{
if (txtbox.value.length >= (MaxLen-1))
{
return false;
}
return true;
}
2. This Can happen in case when Text is pasted directly into textbox. as there won't be any keystroke. So validator has to be placed
Multiple code has to be placed to handle this problem.
1.Use JavaScript to validate on each keystroke
add this to HTML tag of textbox
onKeyPress="return ValidateMultiLineTextboxMaxLength(this,250);"
JS for above Call
function ValidateMultiLineTextboxMaxLength(txtbox,MaxLen)
{
if (txtbox.value.length >= (MaxLen-1))
{
return false;
}
return true;
}
2. This Can happen in case when Text is pasted directly into textbox. as there won't be any keystroke. So validator has to be placed
Comments
Post a Comment