473,761 Members | 10,365 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Updating character count as user types each character

My VB.NET web application has a textbox where the user is allowed to
enter up to 50 characters. I have a label on the form next to the
textbox that tells the user how many remaining characters he can
enter. This label needs to be refreshed on the fly each time the user
types a character into the text box.

Eventually, the user will click the SAVE button on the web form, and
the data he entered in the text box will be written to the database.

1. How can I get the label to refresh each time the user types a
character? I know I need JavaScript to accomplish this, but the
examples I tried do not work.

2. How can I get the server side code-behind (aspx.vb file) to read
the value of the client-side JavaScript textbox so that I can write
its value to the database?

Thanks for your help.
Jul 21 '05 #1
9 2542
Cor
Hi,

First of all this link,

http://www.microsoft.com/downloads/d...displaylang=en

I would look generaly for your question in the aspnet section of this Server
control validation if I had this problem.

And than maybe you can use a server side control, so the other questions
about the javascript disapear.

I hope this helps?

Cor
Jul 21 '05 #2
Cor wrote:
And than maybe you can use a server side control, so the other
questions about the javascript disapear.


You don't want to have to do a server roundtrip on every key press for
something as simple as this.
--
Tom Porterfield
MS-MVP MCE
http://support.telop.org

Please post all follow-ups to the newsgroup only.
Jul 21 '05 #3
re************* *@nospam.com wrote:
My VB.NET web application has a textbox where the user is allowed to
enter up to 50 characters. I have a label on the form next to the
textbox that tells the user how many remaining characters he can
enter. This label needs to be refreshed on the fly each time the user
types a character into the text box.

Eventually, the user will click the SAVE button on the web form, and
the data he entered in the text box will be written to the database.

1. How can I get the label to refresh each time the user types a
character? I know I need JavaScript to accomplish this, but the
examples I tried do not work.
Take a look at this piece of HTML:

<HTML>
<HEAD>
<SCRIPT LANGUAGE="javas cript">
function setRemainingCha rs()
{
remainingChars. innerText=myInp ut.maxLength-myInput.value.l ength;
}
</SCRIPT>
</HEAD>
<BODY ONLOAD="javascr ipt:remainingCh ars.innerText=m yInput.maxLengt h;">
<INPUT TYPE="TEXT" MAXLENGTH=50 ID="myInput"
ONKEYUP="setRem ainingChars();" ></INPUT>
<SPAN ID="remainingCh ars"></SPAN>
</BODY>
</HTML>
2. How can I get the server side code-behind (aspx.vb file) to read
the value of the client-side JavaScript textbox so that I can write
its value to the database?


Place it in the form tag that gets posted back to the server. If you want
to access using a server side object then specify for the control to runat
server.
--
Tom Porterfield
MS-MVP MCE
http://support.telop.org

Please post all follow-ups to the newsgroup only.
Jul 21 '05 #4
Cor
Hi Tom,
And than maybe you can use a server side control, so the other
questions about the javascript disapear.


You don't want to have to do a server roundtrip on every key press for
something as simple as this.


Did I say that,

Have a look at this

http://www.microsoft.com/downloads/d...displaylang=en

Validating.

And take a dotnet approach.

Cor
Jul 21 '05 #5
Cor wrote:
And than maybe you can use a server side control, so the other
questions about the javascript disapear.
You don't want to have to do a server roundtrip on every key press
for something as simple as this.


Did I say that,

Have a look at this

http://www.microsoft.com/downloads/d...displaylang=en
Validating.

And take a dotnet approach.


That link only takes me to the download for the .NET Framework 1.1 SDK, not
any documentation or recommendations . But if you want to update on the
screen with each and every key press you can't do that server side without
round trips between each key press. I'm not sure how you would accomplish
this with validation controls as they don't hook the the keyup/down/press
events AFAIK.
--
Tom Porterfield
MS-MVP MCE
http://support.telop.org

Please post all follow-ups to the newsgroup only.
Jul 21 '05 #6
Cor
Maybe,

But I did not say take a roundtrip, you can also do something as this.
\\\
Private Sub Page_Load(ByVal sender As System.Object, _
ByVal e As System.EventArg s) Handles MyBase.Load
Me.TextBox1.Att ributes("onkeyu p") = _
"javascript:Rem aining();"
Dim scriptString As String = "<script language=JavaSc ript>" & _
"function Remaining(){" & _
"if (document.all(' Textbox1').valu e.length <51) { " & _
"document.all(' label').innerTe xt=50-document.all " & _
"('Textbox1').v alue.length;}" & _
"else {document.all(' Textbox1').valu e = " & _
"document.all(' Textbox1').valu e.substring(0,5 0) }}" & _
"</script>"
RegisterStartup Script("Startup ", scriptString)
End Sub
//
And still use the serverside controls (I used a HTML label because that does
nothing).

I did a time not use the validating (and I am lazy so probably I would do it
like this), but I think it is the best to tell the OP first to point to the
documentation.

But just my thougth,

Cor
Jul 21 '05 #7
Cor wrote:
Maybe,

But I did not say take a roundtrip, you can also do something as this.
\\\
Private Sub Page_Load(ByVal sender As System.Object, _
ByVal e As System.EventArg s) Handles MyBase.Load
Me.TextBox1.Att ributes("onkeyu p") = _
"javascript:Rem aining();"
Dim scriptString As String = "<script language=JavaSc ript>" &
_ "function Remaining(){" & _
"if (document.all(' Textbox1').valu e.length <51) { " & _
"document.all(' label').innerTe xt=50-document.all " & _
"('Textbox1').v alue.length;}" & _
"else {document.all(' Textbox1').valu e = " & _
"document.all(' Textbox1').valu e.substring(0,5 0) }}" & _
"</script>"
RegisterStartup Script("Startup ", scriptString)
End Sub
//
And still use the serverside controls (I used a HTML label because
that does nothing).
But all you're doing is writing the javascript out from the server rather
than placing it directly in the HTML. This can be beneficial if the
javascript code might change based on some other variables that are only
known server side. For static client-side script that doesn't change this
can be hard to maintain and cause a small amount of unnecessary server
execution on every page load event, the end result being you are still just
executing client side javascript to update the value on the screen, making
your comment about a .NET solution making javascript questions disappear not
accurate. Even .NET validation controls just use javascript clientside for
client-side validation and it's important to understand how that works
before relying on it too much to do these types of things that are generally
outside of typical validation that is done with validation controls.
I did a time not use the validating (and I am lazy so probably I
would do it like this), but I think it is the best to tell the OP
first to point to the documentation.

I agree, but you are linking to the Framework SDK, not any specific
documentation relevant to the original question.
--
Tom Porterfield
MS-MVP MCE
http://support.telop.org

Please post all follow-ups to the newsgroup only.
Jul 21 '05 #8
Cor
Hi Tom,

No I use a serverside textbox control.

That is the big difference.

(And keep the program code isolated in the aspx.vb page yes, but that is not
the big difference, I did also some extra checking to prevent that it where
more than 50 characters also not important.)

Cor
Jul 21 '05 #9
Thanks for all your responses. I downloaded the .NET SDK and will
check there first from now on.

The code sample that Cor posted works great!

On Fri, 20 Feb 2004 01:54:34 -0600, "re************ **@nospam.com"
<se*@website.co m> wrote:
My VB.NET web application has a textbox where the user is allowed to
enter up to 50 characters. I have a label on the form next to the
textbox that tells the user how many remaining characters he can
enter. This label needs to be refreshed on the fly each time the user
types a character into the text box.

Eventually, the user will click the SAVE button on the web form, and
the data he entered in the text box will be written to the database.

1. How can I get the label to refresh each time the user types a
character? I know I need JavaScript to accomplish this, but the
examples I tried do not work.

2. How can I get the server side code-behind (aspx.vb file) to read
the value of the client-side JavaScript textbox so that I can write
its value to the database?

Thanks for your help.


Jul 21 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
4107
by: Daniel Pryde | last post by:
Hi there. I hope this isn't a stupid question to ask, but does anyone know how to print out a string without moving to a new line each time and simply updating the first line. An example would be, if I wanted to have a percentage progress counter that was constantly updating. I'm unsure how to do this without printing to a brand new line. Any help would be greatly appreciated. Thanks. Daniel
9
10118
by: Jerry | last post by:
In limiting textbox input to 500 characters I would like to include a dynamic count of characters input while the user is typing into a textbox. This would obviously be a client side control, possibly a custom validator with a function written in javascript. Has anyone done this? Does someone have an example? Regards
7
2578
by: MgGuigg | last post by:
Hello all, This is my first time posting a question to this forum, so here is hoping I am following protocol. I am scraping the rust off my old Basic programming skills, and have just recently upgraded to VB.NET, and I have a lot of catching up to do. That being said, I have come a long way in a short while, however, I am stumped at the moment. I have read through days of posts, but have not been able to address my specific question, so...
9
400
by: refer_to_website | last post by:
My VB.NET web application has a textbox where the user is allowed to enter up to 50 characters. I have a label on the form next to the textbox that tells the user how many remaining characters he can enter. This label needs to be refreshed on the fly each time the user types a character into the text box. Eventually, the user will click the SAVE button on the web form, and the data he entered in the text box will be written to the...
14
2961
by: el_sid | last post by:
Our developers have experienced a problem with updating Web References in Visual Studio.NET 2003. Normally, when a web service class (.asmx) is created, updating the Web Reference will utilise the disco file to update the Corresponding proxy file and reflect the changes made to the web service. However, the results of doing this with out params is that the results seem
6
3486
by: @sh | last post by:
Guys, Working on a function to alert the user to too many characters being entered into a text area, I've put together this function so far borrowing bits from resource websites... function Ash_LimitMaxTextAreaCharacters(TheMaxCharacters,TheFriendlyFormName) { if(document.myform.box.value.length > TheMaxCharacters) { alert('Sorry but '+TheFriendlyFormName+' contains too many characters,
2
2075
by: WhiteWizard | last post by:
This should be easy, and it probably is, I just can't find anything on it. I have to build an XML Document object in memory, add some child nodes, save it, and then if another condition arises, reload the same xml document and append some more child nodes. And by the way, the user requires that I save between all these occurances so I can't just leave it in memory and then save it just once. So far everything works exactly as I need...
33
3351
by: bill | last post by:
In an application I am writing the user can define a series of steps to be followed. I save them in a sql database using the field "order" (a smallint) as the primary key. (there are in the range of 20 steps) On the admin page the steps are listed, in "order" order and the user can create new steps and assign an order and all is well. The problem may come in using a renumber function which should take the steps in their current order...
16
7437
by: bgold12 | last post by:
Will newlines ever be standardized? I recently discovered that in a textarea, internet explorer adds \r\n for every newline you enter, while firefox adds \n. I know \r is also used in some places... will this ever be fixed?
0
9531
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9345
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10115
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9905
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8780
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7332
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
1
3881
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3456
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2752
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.