character count

a8le

Well-known member
Joined
Oct 27, 2005
Messages
75
Programming Experience
5-10
Hi all,

I am looking to add "a character counter" to my pages with textboxes. I have tried multiple solutions:

http://www.neowin.net/forum/lofiversion/index.php/t305615.html

http://www.codeproject.com/aspnet/TextBoxCounter.asp?df=100&forumid=247992&exp=0&select=1393971

http://www.shiningstar.net/articles/articles/javascript/dynamictextareacounter.asp?ID=ROLLA

Well those are just a few, I have tried implementing many more.

Regardless, nothing has work. I simply don't get it. I am programming using ASP.net 1.1.

I would appreciate any suggestions or other versions of "a character counter"? Please send me in the right direction...

-a8le
 
What are you actually trying to accomplish because this may be much more simple that you think. Are you trying to do what that one JavaScript page was doing and have another text box that displays the remaining count of characters that you have? What is your goal with this code? That would help me know what is the best way to go about it.
 
What I am trying to do is exampled in the third link of my original post. Well, the Javascript is right but the language is wrong. The first link is more in tune with what I am trying to do because I am programming under ASP.net 1.1.

So far I know the javascript seems simple enough:

VB.NET:
<script LANGUAGE="JavaScript">
function textCounter(field,cntfield,maxlimit) {
if (field.value.length > maxlimit) {
field.value = field.value.substring(0, maxlimit);
}
else {
cntfield.value = maxlimit -
field.value.length;
}
}
</script>

The behind code also seems simple:

VB.NET:
myTextboxID.Attributes("name") = "myTextboxID"
myTextboxID.Attributes("onKeyUp") = "textCounter(myTextboxID,remLen1,90);"
myTextboxID.Attributes("onKeyDown") = "textCounter(myTextboxID,remLen1,90);"
myTextboxID.Attributes("onKeyPress") = "textCounter(myTextboxID,remLen1,90);"

But that didn't work so I tried:

VB.NET:
myTextboxID.Attributes.Add("name", "myTextboxID")
myTextboxID.Attributes.Add("onKeyUp", "textCounter(myTextboxID,remLen1,90);")
myTextboxID.Attributes.Add("onKeyDown", "textCounter(myTextboxID,remLen1,90);")
myTextboxID.Attributes.Add("onKeyPress", "textCounter(myTextboxID,remLen1,90);")

And that didn't work, I am getting javascript errors saying that, myTextboxID is not defined. I am sure it is, everything works without the new code.

From the numerous examples I found on the web, I don't think I even need the onKeyPress attribute:

VB.NET:
myTextboxID.Attributes.Add("onKeyPress", "textCounter(myTextboxID,remLen1,90);")

But then again might, its still not working. :(

Thanks for the reply,
a8le.
 
Check the ClientID property of your "myTextboxID" control, it may not be what you presume it is.
 
This may not help a8le due to the version of .NET that user is using, but for anyone else who stumbles upon this thread; Scott Cate is currently refining a TextBoxCounterExtender control which will soon become part of the ASP.NET AJAX toolkit.
More info can be found here: TextBoxCounter Atlas Extender @ Scott Cate's blog
More information on ASP.NET AJAX can be found here: ASP.NET AJAX
 
Back
Top