Saturday 3 September 2016

ASP.NET - How to Count Character written in TextBox

Posted by : Manav Pandya


ASP.NET How to count characters written in textbox


ASP.NET - How to Count Character written in TextBox  ?

This is one of my unique article that shows action in which when you type any character inside textbox , automatically you can see characters counted below .

For that follow give procedure in visual studio 

1 . Create new project 

2 . Create new Webform by right clicking on solution

3 . Put two control inside Webform 
  • Textbox (to write string / characters)
  • Label (To print total character printed at textbox)
4 . Write JavaScript function as follow 


<head runat="server">
     <title>Remaining Characters Counter</title>
     <script type="text/javascript">
     function Count() 
     {
     var i = document.getElementById("TextBox1").value.length;
     document.getElementById("Label1").innerHTML = 10 - i;
     }
     </script>
</head>

5 . Write Event name of Textbox already you have taken in form

Ex : - onkeyup='(your event name)'

6 .  Call this function


 <asp:TextBox ID="TextBox1" runat="server" 
             MaxLength="10" onkeyup="Count()"> 
  </asp:TextBox>


Great you did it ......

Thanks for reading my article

Keep tune in to get latest articles ......

basic asp.net mvc tutorials, Free asp.net mvc Tutorials for beginners, mvc, asp.net mvc, .net tutorials, mvc tutorial, mvc tutorials, asp.net mvc tutorials, mvc tutorial, mvc tutorials for Beginners , asp.net mvc Basics, basic mvc, mvc4, mvc5,.net mvc