• How to count characters in a Textbox in ASP.NET

    by  • May 16, 2014 • Microsoft .NET C# (C-Sharp), Microsoft ASP.NET, Microsoft VB.NET • 0 Comments

    Many website have their feedback or suggestions and complaint pages so that user can post their feedback, give suggestions and write any complaint. These pages have a multi-line Texbox or text area but they restrict users to write fix number of characters. User cannot exceed from the given fixed number of characters because they want a precise and short feedback. They also show how many characters user has written or left so that users can limit themselves according to fix number of characters. In ASP.NET, you can use a client side JavaScript function to restrict users to a limit and you can also count remaining or written characters and can display on the page. This is a simple and very helpful code snippet which you can copy and put in your JavaScript file or tag.

    Create a new website in visual studio and add a webform in it

    Write below lines of code in aspx page

    I have called a JavaScript function in the onkeyup event of Textbox. This function is defined below.

    Now add following JavaScript function

    Browse the website and write text in Textbox. You will see remaining characters and you cannot write more than fifty characters in Textbox because I have set the limit to fifty. You can set it according to your need. You can also download complete code from below link.




    Namecheap.com
    Avatar of GetCodeSnippet.com

    About

    GetCodeSnippet.com provides you high quality Microsoft .NET development related articles, tutorials and sample code for ASP.NET, C#, VB.NET, AJAX, WCF, WPF, Web Services, Windows Services, SQL Server and other technologies.

    Leave a Reply