Results 1 to 6 of 6

Thread: How to use Character counter in ASP.Net?

  1. #1
    Join Date
    Aug 2009
    Posts
    63

    How to use Character counter in ASP.Net?

    Hello to all,
    I am last year Computer Science student. I am working on project where I am using Asp.net as front end. I have created one text box whose max length is 500. I use regular expression for validation if length of character in text bow exceed 500. But it is very time consuming process. I want to show a counter whose value is decremented from 500 whenever key press event happened on text box. For this reason I want to use Character counter. Can anyone tell me How to use Character counter in ASP.Net?
    Thanks in advanced.
    Last edited by kamina23; 25-01-2010 at 05:49 PM.

  2. #2
    Join Date
    Apr 2008
    Posts
    1,948

    Re: How to use Character counter in ASP.Net?

    You have to use one label with width properly set to display a smaller space besides the textbox. After doing this assign the text of the label with the lenght of the textbox length as follows: Just copy this code and save it in your project. Now try to run that program. I have just use ToInt32 for converting number into character.
    Code:
    keypress event
    
    {
    
    l1.Text = TextB1.Text.Length; 
    
    or
    
    l1.Text = (500 -  Convert.ToInt32(TextB1.Text.Length)).ToString(); 
    
    }
    Last edited by Praetor; 25-01-2010 at 06:00 PM.

  3. #3
    Join Date
    May 2008
    Posts
    2,012

    Re: How to use Character counter in ASP.Net?

    Hey you can use following code to accomplish this. It is good idea to tell the user how many characters they have remaining when you use Character counter. The following code is especially useful for textarea fields . Just try to understand each step.
    Code:
    <script language = "Javascript">
    
    
    maxLw=500;
    var bName1 = navigator.appName;
    function taLimit(taObj) {
    	if (taObj.value.length==maxLw) return false;
    	return true;
    }
    
    function taCount(taObjs,Cnt) { 
    	objCnts=createObject(Cnt);
    	objVals=taObjs.value;
    	if (objVals.length>maxLw) objVal=objVal.substring(0,maxLw);
    	if (objCnts) {
    		if(bName1 == "Netscape"){	
    			objCnt.textContent=maxLw-objVals.length;}
    		else{objCnt.innerText=maxLw-objVals.length;}
    	}
    	return true;
    }
    function createObject(objIds) {
    	if (document.getElementById) return document.getElementById(objIds);
    	else if (document.layers) return eval("document." + objIds);
    	else if (document.all) return eval("document.all." + objIds);
    	else return eval("document." + objIds);
    }
    </script>

  4. #4
    Join Date
    Apr 2008
    Posts
    2,005

    Re: How to use Character counter in ASP.Net?

    Hey it is very easy process. You have to use MaxLength property in your project. When you use MaxLength property user will not be able to type beyond the specified length. It is available in ASP.NET server control. You have to use onkeydown event of the textbox to do this. Now set the javascript function to the TextBox of your project and set label control below the textbox to display the character count as shown in the following code.

    <input type="text1" name="ourText" onkeydown="DisplayCount()">
    <label id="displayLabel"></label>

  5. #5
    Join Date
    May 2008
    Posts
    2,297

    Re: How to use Character counter in ASP.Net?

    Character counter is mostly used in comments, discussion purpose on browser. It is free area where user is allowed to write anything. You have to assign Character counter to text field for preventing user from entering more than 500 character. Just try to understand following example. It is one of the mos simple program.




    Code:
    Page load event:
    
    TextB1.Attributes.Add("javascript:onkeydown();", "DisplayCount();");
    
    TextB1.Attributes.Add("javascript:onkeypress();", "DisplayCount();");
    
    ASPX. Page
    
    <script language="Javascript">
    
    function DisplayCount()
    
    { var length1 = document.getElementByName("TextB1").value.length;
    
    
    document.getElementByName("Label2").value = length1;
    
    alert(length1);
    
    }</script>

  6. #6
    softtrickseo Guest

    Re: How to use Character counter in ASP.Net?

    hi
    you can use javascript ya JQUERY for this.
    JQUERY profide javascript file for charactercount to every enter character in textbox.

    and javascript.
    getdocument.ByID["textbox"].lenth funtion you can count character

Similar Threads

  1. Replies: 3
    Last Post: 11-02-2012, 12:34 AM
  2. Replies: 8
    Last Post: 06-10-2011, 11:27 PM
  3. Replies: 7
    Last Post: 02-10-2011, 07:46 PM
  4. Replies: 3
    Last Post: 23-09-2011, 02:27 PM
  5. Counter Strike v1.6 or Counter Strike Source
    By Ryder Allen in forum Video Games
    Replies: 5
    Last Post: 03-03-2011, 10:22 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,711,654,369.49110 seconds with 17 queries