Thursday, 28 March 2013

Count TextBox Characters in Realtime


Count TextBox Characters in Realtime


http://www.dotneter.com/count-textbox-characters-in-realtime


Count TextBox Characters in Realtime thumb Count TextBox Characters in Realtime

Counting Characters Realtime in ASP.NET TextBox Using JavaScript
ASPX file
<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title></title>
    
<script type="text/javascript">
    function countCharacters() {
        var count = parseInt(document.getElementById('<%=TextBox1.ClientID%>').value.length);
        document.getElementById('<%=Label1.ClientID%>').innerHTML = 100 - count;
    }
</script>
 
    <style type="text/css">
        .style1
        {
            color: #FF0000;
        }
    </style>
 
</head>
 
<body>
    <form id="form1" runat="server">    
    <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
    <br />
    Max 100 characters<br />
    <span class="style1">Characters left:</span>
    <asp:Label ID="Label1" runat="server"></asp:Label>
    </form>
 
    </body>
</html>

ASPX.CS file
protected void Page_Load(object sender, EventArgs e)
{
    TextBox1.Attributes.Add("onKeyUp", "countCharacters()");
}
Tags: asp net show a counter in realtime, asp net textbox realtime, how to count character from textbox in asp net, how to count characters in a text box asp, how to get TextBox Count in aspx file, count characters textbox multipleline asp, use counter from textbox c#, text counter javascript for textbox using c#, showing real time in asp net textbox, javascript change text in a textboxreal time

No comments:

Post a Comment