1. 问题 在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>
<asp:Button id="btnOK" runat="server" BorderWidth="1px" BorderColor="Purple" BorderStyle="Solid" Text="Search Site"></asp:Button>
2. 解答
在.aspx页面中添加:
<SCRIPT LANGUAGE="j***ascript">
function SubmitKeyClick(button)
{
if (event.keyCode == 13)
{
event.keyCode=9;
event.returnValue = false;
document.all[button].click();
}
}
// -->
</SCRIPT>
在Page_Load事件中添加:
tbInput.Attributes.Add("onkeydown","SubmitKeyClick('btnOK');");