How can make text limiter In with java script

Step 1: Write these lines of code into Page source of default.aspx

<%@ Page Language=”C#” AutoEventWireup=”true”CodeFile=”Default.aspx.cs” Inherits=”_Default” %>
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “”&gt;
<head runat=”server”>
<script  language=”javascript” type=”text/javascript” >
var count = 12;
function limiter()
var tex = document.getElementById(“<%=txtComments.ClientID%>”).value;
var len = tex.length;
if (len > count)
tex = tex.substring(0, count)
document.getElementById(“<%=txtComments.ClientID%>”).value = tex;
return false;
document.getElementById(“limit”).value = count – len;
<form id=”form1″ runat=”server”>
<asp:TextBox ID=”txtComments” runat=”server” Height=”181px”
TextMode=”MultiLine” Width=”267px”></asp:TextBox>
<table border=”0″ cellpadding=”1″ cellspacing=”0″>
<td><script language=”javascript” type=”text/javascript” >
document.write(“<input type=text name=’limit’ id=’limit’ size=4 readonly value=”+count+”>”);</script></td>
<td>Character Remained</td>

Step 2: Now Write Into page load of Page

protected void Page_Load(object sender, EventArgs e)


#region register client scripts

txtComments.Attributes.Add(“onkeyup”, “return limiter();”);



Be happy and Enjoy in Programming World!!

This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

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

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

Google+ photo

You are commenting using your Google+ 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 )


Connecting to %s