Home > ASP.Net, Javascript > Count Characters Remaining in TextBox

Count Characters Remaining in TextBox

Try this example:

<script runat="server">
protected void Page_Load(object sender, EventArgs e)

    txtCount.Text = txtInput.MaxLength.ToString();
       "javascript:document.getElementById('"+ txtCount.ClientID +
       "').setAttribute('value', (" + txtInput.MaxLength +
       " - parseInt(document.getElementById('" + txtInput.ClientID +
public int MaxLength
    get { return txtInput.MaxLength; }
    set { txtInput.MaxLength = value; }

   <asp:Label ID="Label1" runat="server">Characters Left: </asp:Label>
   <asp:TextBox ID="txtCount" runat="server"
            BorderStyle="None" ReadOnly="True">0</asp:TextBox>
   <asp:TextBox ID=txtInput runat="server" BorderColor="Gray"
           BorderStyle="Solid" BorderWidth="1px"
           Height="125px" MaxLength="2000"

Good Luck

Categories: ASP.Net, Javascript
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: