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

Comments

Popular posts from this blog

Shared / Static Class in vb.net/C#

Xamarin Forms : PopUp Page with RG.Plugins.Popup

Text was truncated or one or more characters had no match in the target code page.". (SQL Server Import and Export Wizard)