posted 4/30/2009 by Sumit Arora
I tried to fix the maximum length in multiline textbox by using the property MaxLength. But it didn't work in case of multiline textbox. In this blog i will explain how to get rid of this problem by using jquery.
$(function() { $('#ctl00_ContentPlaceHolder1_txtTest').keyup(function() { limitChars('ctl00_ContentPlaceHolder1_txtTest', 100, 'counter'); }) }); function limitChars(textid, limit, infodiv) { var text = $('#' + textid).val(); var textlength = text.length; if (textlength > limit) { $('#' + infodiv).html('You cannot write more then ' + limit + ' characters!'); $('#' + textid).val(text.substr(0, limit)); return false; } else { $('#' + infodiv).html('You have ' + (limit - textlength) + ' characters left.'); return true; } } <asp:TextBox id="txtTest" runat="server" TextMode="MultiLine"></asp:TextBox > <div id="counter">Max 100 characters.</div>
What kind of email newsletter would you prefer to receive from CodeAsp.Net?18