To work around this problem, use a script to trap the
keypress event and to call the
ButtonClick event when the
keypress event value is
enter.
To do this, follow these steps:
- Add the following script block to the <header> section of the WebForm1.aspx code:
<script language="jscript">
function clickButton()
{
if (event.keyCode == 13)
{
myform.Button1.click();
return false;
}
}
</script>
- Add the onkeypress event for the TextBox control as follows:
<form id="myform" method="post" runat="server">
<asp:TextBox id="TextBox1" onkeypress="return(clickButton());"
ontextchanged="TextBox1_TextChanged" runat="server" AutoPostBack="True"></asp:TextBox>
<asp:Button id="Button1" onclick="Button1_Clicked" runat="server" Text="Button"></asp:Button>
</form>