How to Create an On Key Press Event in Visual Studio 2005
Hi,
I have created a web form in visual Studio 2005. There is a comments text box which I have limited to 500 characters. I would like to display another textbox or label that shows how many characters remain until the max character limit is reached. Every time a character is entered I would like to have the textbox that is counting the characteres be updated. how can I do this using VB?
I am new to VB. Any help would be appreciated.
Thanks!
D-bass
Visual Basic.NETASP.NET
Last Comment
D-bass
8/22/2022 - Mon
GreymanMSC
You do not.
All VB code is handled on the Server side. This is processed only when a page is posted to the browser. You do not want to postback every time you press a key.
You'll need to use Client side scripting to handle such activity; such as VBScript or Javascript.
<script type="text/javascript">document.onkeyup = KeyCheck; function KeyCheck(e){ var txt = document.getElementByID('<%= Me.EntryTextBox.ClientID %>;').getAttribute("value"); document.getElementByID('<%= Me.CountTextBox.ClientID %>').setAttribute("value", txt.length);}</script>
All VB code is handled on the Server side. This is processed only when a page is posted to the browser. You do not want to postback every time you press a key.
You'll need to use Client side scripting to handle such activity; such as VBScript or Javascript.
Open in new window