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 i开发者_如何转开发s decreased by one.
Please help me write a function for this in asp.net using C#.
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;
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);
If you want to update a label with the remaining character count, you would want to use a javascript function. You can add an event handler for a key press on the textbox that updates the text of the label.
You can find more information about capturing the key presses in a textbox here.
I would suggest you to use javascript to do this. in the onkeypress event call a javascript function which will check the length of the content of text box and then update the label in the form.
精彩评论