Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > hitting enter button while in textbox calls correct button's click event

Reply
Thread Tools

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

 
 
TS
Guest
Posts: n/a
 
      11-23-2005
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)


 
Reply With Quote
 
 
 
 
Jeffrey Tan[MSFT]
Guest
Posts: n/a
 
      11-24-2005
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.

 
Reply With Quote
 
 
 
 
=?Utf-8?B?VFM=?=
Guest
Posts: n/a
 
      11-28-2005
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.
>
>

 
Reply With Quote
 
TS
Guest
Posts: n/a
 
      11-28-2005
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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.
>>
>>



 
Reply With Quote
 
TS
Guest
Posts: n/a
 
      11-28-2005
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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.
>>
>>



 
Reply With Quote
 
Jeffrey Tan[MSFT]
Guest
Posts: n/a
 
      11-29-2005
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.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Login control can't fire the button event by hitting enter sowencheung@gmail.com ASP .Net 4 04-20-2006 05:11 AM
Button.Init? how Do I know if click event has been fired? TextBox.TextChanged event before Button.Click in a CompositeCustomControl. jorge ASP .Net Building Controls 1 05-28-2004 06:23 AM
Button.Init? how Do I know if click event has been fired? TextBox.TextChanged event before Button.Click in a CompositeCustomControl. jorge ASP .Net 2 05-25-2004 11:45 PM
Button.Init? how Do I know if click event has been fired? TextBox.TextChanged event before Button.Click in a CompositeCustomControl. jorge ASP .Net Datagrid Control 0 05-25-2004 01:45 AM
Button.Init? how Do I know if click event has been fired? TextBox.TextChanged event before Button.Click in a CompositeCustomControl. jorge ASP .Net Web Controls 0 05-25-2004 01:45 AM



Advertisments