473,977 Members | 2,456 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Hitting Enter in a textbox

As I've mentioned a couple of times in the last few minutes(!), I've got a
simple form with an edit box and a Submit button. If I type something in
the Edit box and hit Enter I hear a click but nothing happens. If I click
on the Submit button its Click event fires as I'd expect. If I click
anywhere else on the web page and then hit Enter, the button's Click event
fires too.

I want the Click event to fire when the user is in the Edit box and hits
Enter. How can I do this?

Thanks for your help.
Nate Hekman
Calgary, Alberta, Canada
Nov 18 '05 #1
9 1904
Is it single line or multiline? If it's multiline it's by design.
You can use clientside code to catch the ENTER press event and call the
button click.

--
Curt Christianson
Owner/Lead Developer, DF-Software
Site: http://www.Darkfalz.com
Blog: http://blog.Darkfalz.com
"Nate Hekman" <he************ *********@nospa m.com> wrote in message
news:%2******** ********@TK2MSF TNGP14.phx.gbl. ..
As I've mentioned a couple of times in the last few minutes(!), I've got a
simple form with an edit box and a Submit button. If I type something in
the Edit box and hit Enter I hear a click but nothing happens. If I click
on the Submit button its Click event fires as I'd expect. If I click
anywhere else on the web page and then hit Enter, the button's Click event
fires too.

I want the Click event to fire when the user is in the Edit box and hits
Enter. How can I do this?

Thanks for your help.
Nate Hekman
Calgary, Alberta, Canada

Nov 18 '05 #2
You can use some javascript to manage it. Add the javascript using the attributes of the control

TextBox1.Attrib utes.Add("onkey down", "javascript:if( (event.which && event.which == 13) || (event.keyCode && event.keyCode == 13)){document.F orm1." & Button1.ClientI D & ".click();retur n false;}else return true;")

(check the name of your HTML form and your controls to get this code to work)

Hope this helps

Alan Ferrandiz [MCT]
"Curt_C [MVP]" <software_AT_da rkfalz.com> escribió en el mensaje news:#u******** ******@TK2MSFTN GP10.phx.gbl...
Is it single line or multiline? If it's multiline it's by design.
You can use clientside code to catch the ENTER press event and call the
button click.

--
Curt Christianson
Owner/Lead Developer, DF-Software
Site: http://www.Darkfalz.com
Blog: http://blog.Darkfalz.com


"Nate Hekman" <he************ *********@nospa m.com> wrote in message
news:%2******** ********@TK2MSF TNGP14.phx.gbl. ..
As I've mentioned a couple of times in the last few minutes(!), I've got a
simple form with an edit box and a Submit button. If I type something in
the Edit box and hit Enter I hear a click but nothing happens. If I click
on the Submit button its Click event fires as I'd expect. If I click
anywhere else on the web page and then hit Enter, the button's Click event
fires too.

I want the Click event to fire when the user is in the Edit box and hits
Enter. How can I do this?

Thanks for your help.
Nate Hekman
Calgary, Alberta, Canada



Nov 18 '05 #3
It's single line. And it does reload the page--I can put a breakpoint in
Page_Load and it breaks when I hit Enter, but it doesn't call
btnSubmit_Click .

"Curt_C [MVP]" <software_AT_da rkfalz.com> wrote in message
news:%2******** ********@TK2MSF TNGP10.phx.gbl. ..
Is it single line or multiline? If it's multiline it's by design.
You can use clientside code to catch the ENTER press event and call the
button click.

--
Curt Christianson
Owner/Lead Developer, DF-Software
Site: http://www.Darkfalz.com
Blog: http://blog.Darkfalz.com
"Nate Hekman" <he************ *********@nospa m.com> wrote in message
news:%2******** ********@TK2MSF TNGP14.phx.gbl. ..
As I've mentioned a couple of times in the last few minutes(!), I've got
a simple form with an edit box and a Submit button. If I type something
in the Edit box and hit Enter I hear a click but nothing happens. If I
click on the Submit button its Click event fires as I'd expect. If I
click anywhere else on the web page and then hit Enter, the button's
Click event fires too.

I want the Click event to fire when the user is in the Edit box and hits
Enter. How can I do this?

Thanks for your help.
Nate Hekman
Calgary, Alberta, Canada


Nov 18 '05 #4
Hello Nate,

I have a post on my website which details how to fix this without any complex javascript, etc.

http://www.mattberther.com/2003/06/000125.html

--
Matt Berther
http://www.mattberther.com
As I've mentioned a couple of times in the last few minutes(!), I've
got a simple form with an edit box and a Submit button. If I type
something in the Edit box and hit Enter I hear a click but nothing
happens. If I click on the Submit button its Click event fires as
I'd expect. If I click anywhere else on the web page and then hit
Enter, the button's Click event fires too.

I want the Click event to fire when the user is in the Edit box and
hits Enter. How can I do this?

Thanks for your help.

Nate Hekman
Calgary, Alberta, Canada


Nov 18 '05 #5
of course not... you didn't call it. You'll have to do some if(IsPostBack)
in the load_page and call the function(s) that are in the button_click

--
Curt Christianson
Owner/Lead Developer, DF-Software
Site: http://www.Darkfalz.com
Blog: http://blog.Darkfalz.com
"Nate Hekman" <he************ *********@nospa m.com> wrote in message
news:uD******** ******@TK2MSFTN GP12.phx.gbl...
It's single line. And it does reload the page--I can put a breakpoint in
Page_Load and it breaks when I hit Enter, but it doesn't call
btnSubmit_Click .

"Curt_C [MVP]" <software_AT_da rkfalz.com> wrote in message
news:%2******** ********@TK2MSF TNGP10.phx.gbl. ..
Is it single line or multiline? If it's multiline it's by design.
You can use clientside code to catch the ENTER press event and call the
button click.

--
Curt Christianson
Owner/Lead Developer, DF-Software
Site: http://www.Darkfalz.com
Blog: http://blog.Darkfalz.com
"Nate Hekman" <he************ *********@nospa m.com> wrote in message
news:%2******** ********@TK2MSF TNGP14.phx.gbl. ..
As I've mentioned a couple of times in the last few minutes(!), I've got
a simple form with an edit box and a Submit button. If I type something
in the Edit box and hit Enter I hear a click but nothing happens. If I
click on the Submit button its Click event fires as I'd expect. If I
click anywhere else on the web page and then hit Enter, the button's
Click event fires too.

I want the Click event to fire when the user is in the Edit box and hits
Enter. How can I do this?

Thanks for your help.
Nate Hekman
Calgary, Alberta, Canada



Nov 18 '05 #6
Hello Curt_C [MVP]" software_AT_dar kfalz.com,

Whoah... No you dont... The event needs to be hooked up and it will be executed somewhere between OnInit and OnLoad...

--
Matt Berther
http://www.mattberther.com
of course not... you didn't call it. You'll have to do some
if(IsPostBack) in the load_page and call the function(s) that are in
the button_click

"Nate Hekman" <he************ *********@nospa m.com> wrote in message
news:uD******** ******@TK2MSFTN GP12.phx.gbl...
It's single line. And it does reload the page--I can put a
breakpoint in Page_Load and it breaks when I hit Enter, but it
doesn't call btnSubmit_Click .

"Curt_C [MVP]" <software_AT_da rkfalz.com> wrote in message
news:%2******** ********@TK2MSF TNGP10.phx.gbl. ..
Is it single line or multiline? If it's multiline it's by design.
You can use clientside code to catch the ENTER press event and call
the
button click.
--
Curt Christianson
Owner/Lead Developer, DF-Software
Site: http://www.Darkfalz.com
Blog: http://blog.Darkfalz.com
"Nate Hekman" <he************ *********@nospa m.com> wrote in message
news:%2******** ********@TK2MSF TNGP14.phx.gbl. ..

As I've mentioned a couple of times in the last few minutes(!),
I've got a simple form with an edit box and a Submit button. If I
type something in the Edit box and hit Enter I hear a click but
nothing happens. If I click on the Submit button its Click event
fires as I'd expect. If I click anywhere else on the web page and
then hit Enter, the button's Click event fires too.

I want the Click event to fire when the user is in the Edit box and
hits Enter. How can I do this?

Thanks for your help.

Nate Hekman
Calgary, Alberta, Canada


Nov 18 '05 #7
Well that starts to get pretty messy pretty fast, because of course if you
DO click the button then first Page_Load gets called, followed by
btnSubmit_Click . If you also call btnSubmit_Click from Page_Load, it gets
called twice.

Matt Berther's fix did the trick for me. Thanks to everyone who offered
advice.
Nate

"Curt_C [MVP]" <software_AT_da rkfalz.com> wrote in message
news:OU******** ******@TK2MSFTN GP10.phx.gbl...
of course not... you didn't call it. You'll have to do some if(IsPostBack)
in the load_page and call the function(s) that are in the button_click

--
Curt Christianson
Owner/Lead Developer, DF-Software
Site: http://www.Darkfalz.com
Blog: http://blog.Darkfalz.com
"Nate Hekman" <he************ *********@nospa m.com> wrote in message
news:uD******** ******@TK2MSFTN GP12.phx.gbl...
It's single line. And it does reload the page--I can put a breakpoint in
Page_Load and it breaks when I hit Enter, but it doesn't call
btnSubmit_Click .

"Curt_C [MVP]" <software_AT_da rkfalz.com> wrote in message
news:%2******** ********@TK2MSF TNGP10.phx.gbl. ..
Is it single line or multiline? If it's multiline it's by design.
You can use clientside code to catch the ENTER press event and call the
button click.

--
Curt Christianson
Owner/Lead Developer, DF-Software
Site: http://www.Darkfalz.com
Blog: http://blog.Darkfalz.com
"Nate Hekman" <he************ *********@nospa m.com> wrote in message
news:%2******** ********@TK2MSF TNGP14.phx.gbl. ..
As I've mentioned a couple of times in the last few minutes(!), I've
got a simple form with an edit box and a Submit button. If I type
something in the Edit box and hit Enter I hear a click but nothing
happens. If I click on the Submit button its Click event fires as I'd
expect. If I click anywhere else on the web page and then hit Enter,
the button's Click event fires too.

I want the Click event to fire when the user is in the Edit box and
hits Enter. How can I do this?

Thanks for your help.
Nate Hekman
Calgary, Alberta, Canada



Nov 18 '05 #8
I didn't specifically mean it could ONLY be from the load, just trying to
say that he needed to put in a catch in the load sequence.....ge esh....

--
Curt Christianson
Owner/Lead Developer, DF-Software
Site: http://www.Darkfalz.com
Blog: http://blog.Darkfalz.com
"Matt Berther" <mb******@hotma il.com> wrote in message
news:em******** *****@tk2msftng p13.phx.gbl...
Hello Curt_C [MVP]" software_AT_dar kfalz.com,

Whoah... No you dont... The event needs to be hooked up and it will be
executed somewhere between OnInit and OnLoad...

--
Matt Berther
http://www.mattberther.com
of course not... you didn't call it. You'll have to do some
if(IsPostBack) in the load_page and call the function(s) that are in
the button_click

"Nate Hekman" <he************ *********@nospa m.com> wrote in message
news:uD******** ******@TK2MSFTN GP12.phx.gbl...
It's single line. And it does reload the page--I can put a
breakpoint in Page_Load and it breaks when I hit Enter, but it
doesn't call btnSubmit_Click .

"Curt_C [MVP]" <software_AT_da rkfalz.com> wrote in message
news:%2******** ********@TK2MSF TNGP10.phx.gbl. ..

Is it single line or multiline? If it's multiline it's by design.
You can use clientside code to catch the ENTER press event and call
the
button click.
--
Curt Christianson
Owner/Lead Developer, DF-Software
Site: http://www.Darkfalz.com
Blog: http://blog.Darkfalz.com
"Nate Hekman" <he************ *********@nospa m.com> wrote in message
news:%2******** ********@TK2MSF TNGP14.phx.gbl. ..

> As I've mentioned a couple of times in the last few minutes(!),
> I've got a simple form with an edit box and a Submit button. If I
> type something in the Edit box and hit Enter I hear a click but
> nothing happens. If I click on the Submit button its Click event
> fires as I'd expect. If I click anywhere else on the web page and
> then hit Enter, the button's Click event fires too.
>
> I want the Click event to fire when the user is in the Edit box and
> hits Enter. How can I do this?
>
> Thanks for your help.
>
> Nate Hekman
> Calgary, Alberta, Canada

Nov 18 '05 #9
Hello Curt_C [MVP]" software_AT_dar kfalz.com,

I suppose I misunderstood.. . I thought you meant he needed to do something like this:

private void Page_Load(objec t sender, EventArgs e)
{
if (Page.IsPostBac k)
{
Button_Click(su bmitButton, EventArgs.Empty );
}
}

which, of course, is completely wrong...

--
Matt Berther
http://www.mattberther.com
I didn't specifically mean it could ONLY be from the load, just trying
to say that he needed to put in a catch in the load
sequence.....ge esh....

"Matt Berther" <mb******@hotma il.com> wrote in message
news:em******** *****@tk2msftng p13.phx.gbl...
Hello Curt_C [MVP]" software_AT_dar kfalz.com,

Whoah... No you dont... The event needs to be hooked up and it will
be executed somewhere between OnInit and OnLoad...

--
Matt Berther
http://www.mattberther.com
of course not... you didn't call it. You'll have to do some
if(IsPostBack) in the load_page and call the function(s) that are
in the button_click

"Nate Hekman" <he************ *********@nospa m.com> wrote in message
news:uD******** ******@TK2MSFTN GP12.phx.gbl...

It's single line. And it does reload the page--I can put a
breakpoint in Page_Load and it breaks when I hit Enter, but it
doesn't call btnSubmit_Click .

"Curt_C [MVP]" <software_AT_da rkfalz.com> wrote in message
news:%2******** ********@TK2MSF TNGP10.phx.gbl. ..

> Is it single line or multiline? If it's multiline it's by design.
> You can use clientside code to catch the ENTER press event and
> call
> the
> button click.
> --
> Curt Christianson
> Owner/Lead Developer, DF-Software
> Site: http://www.Darkfalz.com
> Blog: http://blog.Darkfalz.com
> "Nate Hekman" <he************ *********@nospa m.com> wrote in
> message
> news:%2******** ********@TK2MSF TNGP14.phx.gbl. ..
>> As I've mentioned a couple of times in the last few minutes(!),
>> I've got a simple form with an edit box and a Submit button. If
>> I type something in the Edit box and hit Enter I hear a click
>> but nothing happens. If I click on the Submit button its Click
>> event fires as I'd expect. If I click anywhere else on the web
>> page and then hit Enter, the button's Click event fires too.
>>
>> I want the Click event to fire when the user is in the Edit box
>> and hits Enter. How can I do this?
>>
>> Thanks for your help.
>>
>> Nate Hekman
>> Calgary, Alberta, Canada


Nov 18 '05 #10

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

Similar topics

10
4431
by: Deano | last post by:
I think that just about sums it up. Is there a fix/workaround for this?It's quite annoying behaviour and not user-friendly.thanksMartin
2
3134
by: 23s | last post by:
My site's login page has a form w/ 2 textboxes and a submit button. If I'm in either of those textboxes (i.e., either one of the textboxes has focus), in any given browser, hitting "enter" on my keyboard submits the form. Server side, I handle the click event of the submit button. This is the expected behavior, and this is the behavior irrespective of what browser I use on the login page. However... I have different page that is an...
3
1532
by: PJ6 | last post by:
I want to be able to, depending on the state of the page, direct what the ENTER key causes the page to do. The problem I'm having is I have a user control with a textbox and an "enter" button. If this control is in a certain state, when the user hits the ENTER key on that page, I want the ENTER event to be sent to the ENTER button in that control, like the defuault button-clicking behavior I'm seeing when a button is in the form istelf...
5
8012
by: TS | last post by:
for some reason, it posts to the server, but no click events of any buttons on form fire. the button is the first one on the form. when the focus is inside the textbox, it doesnt' work. if i click the form, it works fine. how do i make it fire the click event of this button? (i have it on a diff. page and it works fine...can't figure out why it is diff. here) thanks to all! (i tried tab order)
5
22735
by: Dundealing | last post by:
I have a single button on my form, and when I press the Enter key while a TextBox has focus I want the Button.Click event to fire. Is there a simple way to do this ?
4
2765
by: sowencheung | last post by:
Hi, all The scenario is like this: I have a master page, contains two user controls, one is a search control, another is a login control. The server-side <form> is in the master page, that's of course. It seems the search control is rendered first, when I stay in the
1
2103
by: gferreri | last post by:
Hi all, I've stumbled on an interesting problem with the way Firefox handles form submitting with the enter key. I'm putting together a page that has one form element with multiple controls with their own textbox field and submit imagebuttons. I've set up each control in an asp:Panel with their DefaultButton property set to the proper button, so when the enter key is pressed, the proper button event handler is triggered. This works...
5
1676
by: id10t error | last post by:
I have a program where were are scanning bar codes for a scanner hooked up to a laptop via USB. The scanner adds the CRLF at the end of every scan. I need to figure out how to make the program to caputer the number scanned so i can use it in my program. Right now i have them scanning the item and then hitting a button on the form to enter the number and I want to make it so they do not have to hit the button. Can anyone help me on this.
2
1690
by: Sunfire | last post by:
I was wondering if there was a way to hit enter to insert blank lines while in the designer? I tried this but all it seems to want to do is insert code that really shouldn't be there. For example, I had a heading 1 centered on a page. Right under that I had some words in smaller print right under the heading. When I hit enter after the heading 1, it automatically put the text right below it in a <p></ptag. I don't want this sort of stuff to...
0
10356
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
10172
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
11823
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...
0
11409
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
11578
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,...
1
8464
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
6560
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
5158
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
2
4732
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.