Monday, June 3, 2024
Homepage · c#
 Popular · Latest · Hot · Upcoming
6
rated 0 times [  13] [ 7]  / answers: 1 / hits: 147540  / 13 Years ago, tue, may 10, 2011, 12:00:00
<asp:UpdatePanel ID=UpdatePanel1 runat=server UpdateMode=Conditional>
<ContentTemplate>
<asp:TextBox ID=TextBox1 runat=server></asp:TextBox>
<asp:Button ID=Button1 runat=server onclick=Button1_Click Text=Send />
</ContentTemplate>
</asp:UpdatePanel>


I have to perform Button1 click event when user press Enter key in Textbox1


More From » c#

 Answers
59

In the aspx page load event, add an onkeypress to the box.



this.TextBox1.Attributes.Add(
onkeypress, button_click(this,' + this.Button1.ClientID + '));


Then add this javascript to evaluate the key press, and if it is enter, click the right button.



<script>
function button_click(objTextBox,objBtnID)
{
if(window.event.keyCode==13)
{
document.getElementById(objBtnID).focus();
document.getElementById(objBtnID).click();
}
}
</script>

[#92308] Monday, May 9, 2011, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
nestorjarettg

Total Points: 451
Total Questions: 108
Total Answers: 108

Location: Rwanda
Member since Thu, Feb 10, 2022
2 Years ago
;