473,469 Members | 1,512 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

hitting enter button while in textbox calls correct button's click event

TS
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)
Nov 23 '05 #1
5 7983
Hi TS,

Thanks for your post.

Based on my understanding, you want to get the function that: when the user
hits enter key in the textbox, just trigger the server side Button's Click
event.

To achieve this, we have to do some customization at the client side. We
can use javascript to cancel the current enter key press operation, then
programmatically invoke the button.click() method. Also, we can first
associate the client textbox.onkeypress event with the client javascript
code. Below is the demo code:

private void Page_Load(object sender, System.EventArgs e)
{
this.TextBox1.Attributes.Add("onkeypress","button_ click()");
}

<script language="javascript">
function button_click()
{
if(window.event.keyCode==13)
{
var Button1=document.getElementById("Button1");
Button1.click();
window.event.cancel=true;
}
}
</script>

This code works well on my side. Hope it helps

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Nov 24 '05 #2
TS
Thanks i will try that, i'm sure it will work.

Can you tell me though why this is occuring so i can understand the root
cause? Like I said, i have a different page that when I hit enter while
cursor in the textbox, it correctly posts to the server and calls the server
side click event handler and works how i want it, and i'm wondering why it
works there, and not on my other page.

thanks a bunch!

""Jeffrey Tan[MSFT]"" wrote:
Hi TS,

Thanks for your post.

Based on my understanding, you want to get the function that: when the user
hits enter key in the textbox, just trigger the server side Button's Click
event.

To achieve this, we have to do some customization at the client side. We
can use javascript to cancel the current enter key press operation, then
programmatically invoke the button.click() method. Also, we can first
associate the client textbox.onkeypress event with the client javascript
code. Below is the demo code:

private void Page_Load(object sender, System.EventArgs e)
{
this.TextBox1.Attributes.Add("onkeypress","button_ click()");
}

<script language="javascript">
function button_click()
{
if(window.event.keyCode==13)
{
var Button1=document.getElementById("Button1");
Button1.click();
window.event.cancel=true;
}
}
</script>

This code works well on my side. Hope it helps

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Nov 28 '05 #3
TS
Also, why does it post to the server at all? it would seem that if it posts
to the server, then obvioulsy the submit button was clicked, or was a
different event evoked that didn't have an event handler?
"TS" <ma*********@nospam.nospam> wrote in message
news:78**********************************@microsof t.com...
Thanks i will try that, i'm sure it will work.

Can you tell me though why this is occuring so i can understand the root
cause? Like I said, i have a different page that when I hit enter while
cursor in the textbox, it correctly posts to the server and calls the
server
side click event handler and works how i want it, and i'm wondering why it
works there, and not on my other page.

thanks a bunch!

""Jeffrey Tan[MSFT]"" wrote:
Hi TS,

Thanks for your post.

Based on my understanding, you want to get the function that: when the
user
hits enter key in the textbox, just trigger the server side Button's
Click
event.

To achieve this, we have to do some customization at the client side. We
can use javascript to cancel the current enter key press operation, then
programmatically invoke the button.click() method. Also, we can first
associate the client textbox.onkeypress event with the client javascript
code. Below is the demo code:

private void Page_Load(object sender, System.EventArgs e)
{
this.TextBox1.Attributes.Add("onkeypress","button_ click()");
}

<script language="javascript">
function button_click()
{
if(window.event.keyCode==13)
{
var Button1=document.getElementById("Button1");
Button1.click();
window.event.cancel=true;
}
}
</script>

This code works well on my side. Hope it helps

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no
rights.

Nov 28 '05 #4
TS
More info:

I am setting the focus to the textbox on page load so the user can
immediately type in a number they want to search and then hit enter key to
submit. Again this is the exact same steps used on the other page that
functions correctly.

thanks again

"TS" <ma*********@nospam.nospam> wrote in message
news:78**********************************@microsof t.com...
Thanks i will try that, i'm sure it will work.

Can you tell me though why this is occuring so i can understand the root
cause? Like I said, i have a different page that when I hit enter while
cursor in the textbox, it correctly posts to the server and calls the
server
side click event handler and works how i want it, and i'm wondering why it
works there, and not on my other page.

thanks a bunch!

""Jeffrey Tan[MSFT]"" wrote:
Hi TS,

Thanks for your post.

Based on my understanding, you want to get the function that: when the
user
hits enter key in the textbox, just trigger the server side Button's
Click
event.

To achieve this, we have to do some customization at the client side. We
can use javascript to cancel the current enter key press operation, then
programmatically invoke the button.click() method. Also, we can first
associate the client textbox.onkeypress event with the client javascript
code. Below is the demo code:

private void Page_Load(object sender, System.EventArgs e)
{
this.TextBox1.Attributes.Add("onkeypress","button_ click()");
}

<script language="javascript">
function button_click()
{
if(window.event.keyCode==13)
{
var Button1=document.getElementById("Button1");
Button1.click();
window.event.cancel=true;
}
}
</script>

This code works well on my side. Hope it helps

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no
rights.

Nov 28 '05 #5
Hi TS,

This behavior is client browser specific, which do not have a definit way.
I think "Steve C. Orr [MVP, MCSD]" has provided you an informative reply
in "how do i determine what event caused postback" post. Please check it
there. Thanks

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Nov 29 '05 #6

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

Similar topics

5
by: Eric | last post by:
Hi All, I'm very experienced in traditional ASP and am new to (am learning) ASP.NET. FYI: I am initially learning ASP.NET with VB.NET to ease the transition for me. I have encountered what I...
9
by: Nate Hekman | last post by:
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...
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...
11
by: Joe | last post by:
Hello All, I have an ASP.NET page with one Textbox (SearchTextBox) and one ImageButton (SearchButton) server controls. The user can type search text in SearchTextBox and click SearchButton and...
15
by: Adam J. Schaff | last post by:
I have noticed that if a user closes a form via pressing return (either while the OK button has focus or if AcceptButton is set to OK for the form) then the "ENTER" keypress event fires ON THE...
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: 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...
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,...
0
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...
1
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
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...
0
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 ...

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.