I'm using javascript on my page to limit the characters that can be entered on a multiline text box:
Code:
<script type="text/javascript">
$(function Comments() {
var limit = 300;
$('textarea[id$=txtAdditionalComments]').keyup(function () {
var len = $(this).val().length;
if (len > limit) {
this.value = this.value.substring(0, limit);
}
$('#spn').text(limit - len + " characters left");
});
});
</script>
My counting control that gets refreshed is:
Code:
<cc1:TextBoxCounter ID="TextBoxCounter1" runat="server" TextBoxControlId="txtAdditionalComments" DataFormatString="({1}/300 characters)" />
My problem is I have update pannels elsewhere on the page which, when refreshed, stops this from running. I can see lots of solutions online for this but not being a javascript guru I just can't seem to get it to work.
I have tried using this in code behind on the page postback:
Code:
ScriptManager.RegisterStartupScript(TextBoxCounter1, TextBoxCounter1.GetType, "Comments()", "Comments()", True)
But no luck. Can anyone tell me how I can get this working??