Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to count number of character which is entered in textbox?

Tags:

c#

asp.net

I have a label lblCountCharacter with text "4000" and a textbox txtAddNote where users can enter text.

On entering one character in txtAddNote, the label text is decreased by one.

Please help me write a function for this in asp.net using C#.

like image 527
Shalni Avatar asked Nov 02 '10 14:11

Shalni


2 Answers

In order to avoid post backs you can use jQuery to determine the length of the text in the text box:

var myLength = $("#myTextbox").val().length;
like image 110
Miyagi Coder Avatar answered Nov 12 '22 18:11

Miyagi Coder


I think you can get a better solution to this by using just javascript/jQuery. Using c# is going to involve having to use AJAX to re-render the Label each time.

var characterLimit = 4000
var charLeft = characterLimit - $(".textbox").val().length
$(".label").html(charLeft);
like image 37
Curtis Avatar answered Nov 12 '22 17:11

Curtis