Click here to Skip to main content
15,615,155 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello all

I created a how to count the character left to type

The JavaScript code is

XML
<script type="text/javascript" language="javascript">
    function validatelimit(obj, maxchar)
     {
        if (this.id) obj = this;
        var remaningChar = maxchar - obj.value.length;
        document.getElementById('<%= Label1.ClientID %>').innerHTML = remaningChar;
        if (remaningChar <= 0) {
            obj.focus();
            obj.value = obj.value.substring(maxchar, 0);
            alert('Character Limit exceeds!');
            return false;
        }
        else
        { return true; }
    }
</script>


In asp source file,
<asp:TextBox ID="txt_Skill" runat="server" TextMode="MultiLine" onkeyup="validatelimit(this,50)"></asp:TextBox>


It is working but when i am refreshing the page that time the label contains the maxvalue as 255.

I want how i disable the writing character after 255 no of character.

Any body help me
Posted
Updated 9-Dec-10 22:35pm
v2
Comments
TweakBird 10-Dec-10 4:35am    
Minor edit for spells & code block.

Try this which is simple

Max Length in Multiline TextBox in Asp.Net[^]
 
Share this answer
 
Are you sure that you didn't change value from backend in postback?
 
Share this answer
 
Use MaxLength property of text box....I believe it will solve your problem
 
Share this answer
 
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900