Counting characters real time


I am trying to come up with a code that can count the characters in a textbox in C#. Here is what I have now. But it does not seem to work. Also, according to what I found online, OnTextChanged only works when the cursor leaves the field. ??thanks

            <asp:TextBox id="Notes" maxlength="10"  OnTextChanged="textBox_KeyPress" runat="server"  Width="496px" rows="20" TextMode="MultiLine"></asp:TextBox>      
            <asp:Label id="NotesRemaining" runat="server"></asp:Label>  characters remaining	

Open in new window

    protected void textBox_KeyPress(object sender, EventArgs e)

        //var max = 100;
        //var countNow = Notes.Text.Length;
        NotesRemaining.Text = "aaaa";// (max - countNow) + " Characters remaining";

Open in new window

Who is Participating?
Ryan ChongConnect With a Mentor Commented:
OnTextChanged will be fired at server end.

to enable real time tracking in JavaScript event, you can look into keypress event, etc.
mcrmgAuthor Commented:
thank you very much
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.