RE: hitting enter button while in textbox calls correct button's click event
- From: v-jetan@xxxxxxxxxxxxxxxxxxxx ("Jeffrey Tan[MSFT]")
- Date: Thu, 24 Nov 2005 02:30:06 GMT
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.
.
- References:
- Prev by Date: Re: streaming binary data from sql 2005
- Next by Date: Re: page vs directory security
- Previous by thread: hitting enter button while in textbox calls correct button's click event
- Next by thread: Re: hitting enter button while in textbox calls correct button's c
- Index(es):