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. 9 2511
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
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. 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="javascript">
function setRemainingChars()
{
remainingChars.innerText=myInput.maxLength-myInput.value.length;
}
</SCRIPT>
</HEAD>
<BODY ONLOAD="javascript:remainingChars.innerText=myInpu t.maxLength;">
<INPUT TYPE="TEXT" MAXLENGTH=50 ID="myInput"
ONKEYUP="setRemainingChars();"></INPUT>
<SPAN ID="remainingChars"></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.
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
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.
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.EventArgs) Handles MyBase.Load
Me.TextBox1.Attributes("onkeyup") = _
"javascript:Remaining();"
Dim scriptString As String = "<script language=JavaScript>" & _
"function Remaining(){" & _
"if (document.all('Textbox1').value.length <51) { " & _
"document.all('label').innerText=50-document.all " & _
"('Textbox1').value.length;}" & _
"else {document.all('Textbox1').value = " & _
"document.all('Textbox1').value.substring(0,50 ) }}" & _
"</script>"
RegisterStartupScript("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
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.EventArgs) Handles MyBase.Load Me.TextBox1.Attributes("onkeyup") = _ "javascript:Remaining();" Dim scriptString As String = "<script language=JavaScript>" & _ "function Remaining(){" & _ "if (document.all('Textbox1').value.length <51) { " & _ "document.all('label').innerText=50-document.all " & _ "('Textbox1').value.length;}" & _ "else {document.all('Textbox1').value = " & _ "document.all('Textbox1').value.substring(0,50 ) }}" & _ "</script>" RegisterStartupScript("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.
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
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.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.
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. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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,...
|
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,...
|
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...
|
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...
|
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...
|
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...
|
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,...
|
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...
|
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...
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
| |