I\'m trying to use asp:
I want a way to spe
Nearly all modern browsers now support the use of the maxlength attribute for textarea elements.(https://caniuse.com/#feat=maxlength)
To include the maxlength attribute on a multiline TextBox, you can simply modify the Attributes collection in the code behind like so:
txtTextBox.Attributes["maxlength"] = "100";
If you don't want to have to use the code behind to specify that, you can just create a custom control that derives from TextBox:
public class Textarea : TextBox
{
public override TextBoxMode TextMode
{
get { return TextBoxMode.MultiLine; }
set { }
}
protected override void OnPreRender(EventArgs e)
{
if (TextMode == TextBoxMode.MultiLine && MaxLength != 0)
{
Attributes["maxlength"] = MaxLength.ToString();
}
base.OnPreRender(e);
}
}