473,387 Members | 1,492 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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 10192
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*******@hotmail.com> wrote in message
news:OF**************@TK2MSFTNGP11.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(submitBtn) {
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="submitOnEnter(this.form.submitBtn1)">
<input type="submit" name="submitBtn1" value="submit1">
<input type="text" name="myField"
onkeydown="submitOnEnter(this.form.submitBtn2)">
<input type="submit" name="submitBtn2" value="submit2">
</form>
</body>
</html>

So if sumbitOnEnter-script is registered and you want to set some field to
use it
myInput.Attributes.Add("onkeydown","submitOnEnter( this.form." + BUTTONNAME +
")");
Where BUTTONNAME is the button (surprise ;) ) to click

--
Best Regards
Vidar Petursson
==============================
Microsoft Internet Client & Controls MVP
==============================
"DDK" <dd*******@hotmail.com> wrote in message
news:OF**************@TK2MSFTNGP11.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
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...
8
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...
15
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...
5
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...
1
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...
8
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...
5
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...
0
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...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
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...
0
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...
0
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
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...
0
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,...
0
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...
0
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,...

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.