[摘录]asp.net回车键的应用与控制.
原文地址: http://www.cnblogs.com/witer666/archive/2007/11/06/950845.html
作者: witer666
1.按回车键不提交数据。
if (window.event.keyCode == 13)
{
event.returnValue=false;
event.cancel = true;
}
2.在文件框中按回车键触发提交事件
TextBox1.Attributes.Add("onkeydown", "if(event.which || event.keyCode){if ((event.which == 13) || (event.keyCode == 13)) {document.getElementById('"+Button1.UniqueID+"').click();return false;}} else {return true}; ");
3.ASP.NET2.0中网页打开设置一个默认的按钮焦点
<form defaultbutton="button1" runat="server">
<asp:textbox id="textbox1" runat="server"/>
<asp:textbox id="textbox2" runat="server"/>
<asp:button id="button1" text="Button1" runat="server"/>
<asp:panel defaultbutton="button2" runat="server">
<asp:textbox id="textbox3" runat="server"/>
<asp:button id="button2" runat="server"/>
</asp:panel>
</form>
Trackback:http://www.beansoftware.com/ASP.NET-Tutorials/Accept-Enter-Key.aspx