Maxlength not working in textbox multiline mode
In asp.net textbox, when we select textbox to multiline, it will not take max length, so we have to write code on server side. But if we use single line textbox, maxlength property will work.
aspx code
<div>
<asp:TextBox ID="tb_accomplishment" runat="server" ClientIDMode="Static" TextMode="MultiLine" CssClass="form-control" Rows="5" MaxLength="750" onkeyup="maxLengthCharCount(this)" xmlns:asp="#unknown"></asp:TextBox><span id="rchars">750</span> Character(s) Remaining
</div>
aspx.cs code
if (!IsPostBack)
{
tb_accomplishment.Attributes.Add("maxlength", tb_accomplishment.MaxLength.ToString());
}
javascript code
function maxLengthCharCount(e) {
debugger
var maxLength = e.maxLength;
var textlen = maxLength - e.textLength;
$('#rchars').text(textlen);
}
</script>
ref:- https://www.w3resource.com/jquery-exercises/part1/jquery-practical-exercise-9.php
https://stackoverflow.com/questions/42266685/asp-net-multiline-textbox-maxlength
https://www.c-sharpcorner.com/blogs/set-maxlength-property-to-multiline-textbox1
No comments:
Post a Comment