Tags
ASP, ASP.NET, HTML, JavaScript, JQuery, Programming, Text box, Tools
Oh my god, spend few hours trying to clear ASP.Net TextBoxes using JQuery and yes Done but when it comes with TextMode=”MultiLine” I was searching on net and my head, couldn’t believe it, what’s wrong and then found an Article told me what’s wrong…
http://www.dotnetcurry.com/ShowArticle.aspx?ID=396
<html xmlns=”http://www.w3.org/1999/xhtml”>
<head id=”Head1″ runat=”server”>
<title>Limit Characters in a Multiline TextBox</title>
<script type=’text/javascript’ src=’http://jqueryjs.googlecode.com/files/jquery1.3.2.min.js’></script>
<script type=”text/javascript”>
$(function() {
var limit = 50;
$(‘textarea[id$=tb1]’).keyup(function() {
var len = $(this).val().length;
if (len > limit) {
this.value = this.value.substring(0, limit);
}
$(‘#spn).text(limit – len + ” characters left”);
});
});
</script>
</head>
<body>
<form id=”form1″ runat=”server”>
<div>
<asp:TextBox ID=”tb1″ runat=”server” TextMode=”MultiLine”/><br />
<span id=”spn “></span>
</div>
</form>
</body>
</html>
The Best Part is Below:
Observe how we are selecting the control using textarea in the code shown above $(‘textarea[id$=tb1]’). This is as the ASP.NET Multiline TextBox renders as a textarea.