Monday 24 February 2014

Count Number of Character in Multiline Textbox - Part II

Count Number of Character in Multiline Textbox - Part II

This post is the continuation of the Previous Post. We are trying to achieve a similar functionality using an alternative method.

Note: This is a Cross Browser Compatible Approach[Tested in IE,FF and Chrome].

Code Snippet:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">

<html xmlns="">
<head runat="server">
    <title>Count Number of Character Multiline Textbox II</title>
    <script type="text/javascript" language="Javascript">
        //Character count script!
        function textCounter(field, countfield, maxlimit) {
            if (field.value.length > maxlimit)
                field.value = field.value.substring(0, maxlimit);
                countfield.value = maxlimit - field.value.length;
    <form id="form1" runat="server">
    <asp:TextBox ID="uxCommentsNoTextbox" runat="server" Height="100" Width="550" Wrap="true"
           TextMode="MultiLine" onkeyup="textCounter(uxCommentsNoTextbox, this.form.uxCommentsCharCount, 1500);"
           onkeydown="textCounter(uxCommentsNoTextbox, this.form.uxCommentsNoCharCount, 1500);" />
           <br />
           <br />
           <input readonly="readonly" type="text" id="uxCommentsNoCharCount" name="uxCommentsNoCharCount"
       size="4" maxlength="4" value="" style="border: solid 0px white; background: white;" />

No comments:

Post a Comment

Thank You for Your Comments. We will get back to you soon.

back to top