473,667 Members | 2,692 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Textbox, button and Enter on keyboard

DDK
Question (using C# and ASP.NET),

I have a textbox and a buttonClick on my asp.net page. I would
like be able to hit the Enter button on the keyboard and have it do the
same thing as the buttonClick. In other words how do you get Enter button
on the key board to perform the same operation as a button click event.

Any help would be great,
Thanks

D.
Nov 17 '05 #1
2 10204
You can intercept the client side enter keypress event of the text box and
then click
the correct button using javascript code.
Here's a good example:
http://www.kamp-hansen.dk/pages/show...d=21&menuid=18

You could also try using this free control.
http://www.metabuilders.com/tools/DefaultButtons.aspx

--
I hope this helps,
Steve C. Orr, MCSD
http://Steve.Orr.net
"DDK" <dd*******@hotm ail.com> wrote in message
news:OF******** ******@TK2MSFTN GP11.phx.gbl...
Question (using C# and ASP.NET),

I have a textbox and a buttonClick on my asp.net page. I would
like be able to hit the Enter button on the keyboard and have it do the
same thing as the buttonClick. In other words how do you get Enter button
on the key board to perform the same operation as a button click event.

Any help would be great,
Thanks

D.

Nov 17 '05 #2
Hi

Basic example... simply say what submitbutton should be clicked onkeydown
event
I think this will work in netscape also but havent tested it....

<html>
<head>
<SCRIPT>
function submitOnEnter(s ubmitBtn) {
var keyCode = document.all ? event.keyCode :evt.which ? evt.which :
evt.keyCode ? evt.keyCode : evt.charcode;
if (keyCode == 13) submitBnt.click ();
}
</script>
</head>
<body>
<form >
<input type="text" name="myField"
onkeydown="subm itOnEnter(this. form.submitBtn1 )">
<input type="submit" name="submitBtn 1" value="submit1" >
<input type="text" name="myField"
onkeydown="subm itOnEnter(this. form.submitBtn2 )">
<input type="submit" name="submitBtn 2" value="submit2" >
</form>
</body>
</html>

So if sumbitOnEnter-script is registered and you want to set some field to
use it
myInput.Attribu tes.Add("onkeyd own","submitOnE nter(this.form. " + BUTTONNAME +
")");
Where BUTTONNAME is the button (surprise ;) ) to click

--
Best Regards
Vidar Petursson
=============== ===============
Microsoft Internet Client & Controls MVP
=============== ===============
"DDK" <dd*******@hotm ail.com> wrote in message
news:OF******** ******@TK2MSFTN GP11.phx.gbl...
Question (using C# and ASP.NET),

I have a textbox and a buttonClick on my asp.net page. I would
like be able to hit the Enter button on the keyboard and have it do the
same thing as the buttonClick. In other words how do you get Enter button
on the key board to perform the same operation as a button click event.

Any help would be great,
Thanks

D.

Nov 17 '05 #3

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

Similar topics

14
2942
by: Gidi | last post by:
Hi, For the last week, i'm looking for a way to make a TextBox always write in English (No matter what the OS default language is). i asked here few times but the answers i got didn't help me. i search in google and found a way with changing the CultureInfo but still didn't work on a TextBox. i'm sure there's a way to do that, but i don't know what's the way. I'm desperate, if some one knows the answer, i will be very thankful to know...
8
1692
by: Shawn | last post by:
I have an application that will use barcode scanners to enter an ID to search a database. The main form uses a tab page. I would like people to go to the tab for checking in and just read the barcode without having to hit enter. I also want to keep the number hidden, so I don't want it entered into a visible textbox. TabPages don't have a keypress event, so I'm not sure how to handle this. Thanks...
15
12531
by: simonoficina | last post by:
Hello all! I am a vb.net beginner in Spain. When I use VB6 ,the button object has a property called "default" that can set this button like press "ENTER" key. But in the VB.net I can't find this property. Where is it? Or mabye change the other thing,No?Thanks ! Simon
5
7442
by: =?Utf-8?B?QmVuIFIu?= | last post by:
Hi, In a .NET 2.0 winforms application, I've got a textbox that, when updated, uses the validated event to cascade the change to another textbox (along with another value). This works well if the user does indeed move the cursor to another textbox, but if the user clicks my "done" toolstripbutton after making a change in the textbox but without moving the cursor out, the validated event never fires. I have a pretty bad workaround where...
1
7006
by: daonho | last post by:
I tried to use javascript to trigger up the button click function when user press enter key from the textbox. This function work fine with a single button click such has login page. However, if the page has multiple button such login page with a search function somewhere around, then it's not respond properly. I have attached a brief example of two text boxes and two button. When ever a key is press on textbox one, I want to trigger...
8
2053
by: Freddy Coal | last post by:
Hi, I would like make a search and replace in a file, for that I need get the text in a textbox, but I need recognyze literally characters of the user like a commands, for example: The chain of the user is: "Hello world" & chr(64) & vbcrlf If I capture the textbox, I get: ""Hello world" & chr(64) & vbcrlf" But I would like get the string: "Hello world@" & vbcrlf
5
8472
by: michels287 | last post by:
Right now I have a touchscreen with a virual keyboard. I would like to create arrow keys. If the user messed up the inputted text, he can move the blinking cursor left one space at a time between inputted characters to add a letter. Then a button to move the blinking cursor back to the end of the inputted text. Private Sub Left Arrow_Click() If Text1.SelStart Then Text1.SelStart = Text1.SelStart - 1 Text1.SetFocus End Sub Private...
0
1746
by: michels287 | last post by:
I have a masked textbox on my form. I have an onscreen keyboard with numbers only. The masked format for the masked textbox is: (###) ### - #### I want to make sure they enter the phone numbers properly, hence the mask. What I cannot seem to figure out is why can I not send the button captions (captions are the value of the number buttons, 1 through 9) into the masked box without an error? I get: Run Time Error '380'. Invalid...
0
8458
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
8888
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
8565
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
8650
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6206
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...
0
5677
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4202
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4372
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2779
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

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.