473,395 Members | 1,856 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,395 software developers and data experts.

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 1863
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*********************@nospam.com> wrote in message
news:%2****************@TK2MSFTNGP14.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.Attributes.Add("onkeydown", "javascript:if((event.which && event.which == 13) || (event.keyCode && event.keyCode == 13)){document.Form1." & Button1.ClientID & ".click();return 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_darkfalz.com> escribió en el mensaje news:#u**************@TK2MSFTNGP10.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*********************@nospam.com> wrote in message
news:%2****************@TK2MSFTNGP14.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_darkfalz.com> wrote in message
news:%2****************@TK2MSFTNGP10.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*********************@nospam.com> wrote in message
news:%2****************@TK2MSFTNGP14.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*********************@nospam.com> wrote in message
news:uD**************@TK2MSFTNGP12.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_darkfalz.com> wrote in message
news:%2****************@TK2MSFTNGP10.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*********************@nospam.com> wrote in message
news:%2****************@TK2MSFTNGP14.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_darkfalz.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*********************@nospam.com> wrote in message
news:uD**************@TK2MSFTNGP12.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_darkfalz.com> wrote in message
news:%2****************@TK2MSFTNGP10.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*********************@nospam.com> wrote in message
news:%2****************@TK2MSFTNGP14.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_darkfalz.com> wrote in message
news:OU**************@TK2MSFTNGP10.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*********************@nospam.com> wrote in message
news:uD**************@TK2MSFTNGP12.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_darkfalz.com> wrote in message
news:%2****************@TK2MSFTNGP10.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*********************@nospam.com> wrote in message
news:%2****************@TK2MSFTNGP14.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.....geesh....

--
Curt Christianson
Owner/Lead Developer, DF-Software
Site: http://www.Darkfalz.com
Blog: http://blog.Darkfalz.com
"Matt Berther" <mb******@hotmail.com> wrote in message
news:em*************@tk2msftngp13.phx.gbl...
Hello Curt_C [MVP]" software_AT_darkfalz.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*********************@nospam.com> wrote in message
news:uD**************@TK2MSFTNGP12.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_darkfalz.com> wrote in message
news:%2****************@TK2MSFTNGP10.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*********************@nospam.com> wrote in message
news:%2****************@TK2MSFTNGP14.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_darkfalz.com,

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

private void Page_Load(object sender, EventArgs e)
{
if (Page.IsPostBack)
{
Button_Click(submitButton, 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.....geesh....

"Matt Berther" <mb******@hotmail.com> wrote in message
news:em*************@tk2msftngp13.phx.gbl...
Hello Curt_C [MVP]" software_AT_darkfalz.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*********************@nospam.com> wrote in message
news:uD**************@TK2MSFTNGP12.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_darkfalz.com> wrote in message
news:%2****************@TK2MSFTNGP10.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*********************@nospam.com> wrote in
> message
> news:%2****************@TK2MSFTNGP14.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
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
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...
3
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....
5
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...
5
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
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,...
1
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...
5
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...
2
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,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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:
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...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.