asp.net中如何回车触发指定按钮的事件

问题内容:
在asp.Net中,如何回车触发指定按钮的事件?
假设:
<asp:TextBox id="tbInput" runat="server" Width="240px"></asp:TextBox>
<asp:Button id="btnOK" runat="server" BorderWidth="1px" BorderColor="Purple" BorderStyle="Solid" Text="Search Site"></asp:Button>
-----------------------------------------------------------------------------------------------------------------------------

方法一:

直接 TextBox1.Attributes.Add("onkeydown", "if(event.keyCode==13){document.all.Button3.focus();document.all.Button3.click();}");

-----------------------------------------------------------------------------------------------------------------------------

方法二: (这个方法解决了我项目的问题)

在.aspx页面中添加:
<SCRIPT LANGUAGE="Javascript">
function SubmitKeyClick(button)
{   
 if (event.keyCode == 13)
 {       
  event.keyCode=9;
  event.returnValue = false;
  document.all[button].click();
 }
}
// -->
</SCRIPT>

在Page_Load事件中添加:
txtPwd.Attributes.Add("onkeydown", "SubmitKeyClick('"+ImageButton1.ClientID+"');");

原文地址:https://www.cnblogs.com/SALIN/p/1279699.html