How do I associate the Enter key with a button on an aspx page?

╄→尐↘猪︶ㄣ 提交于 2019-12-04 08:25:09

DefaultButton also works in panels, so you can set a default button in each panel and have the Enter key click the button in whichever panel currently has focus.

This is subtle in IE. You'll need to add a textbox to your control, set the display to none, and visibility to hidden which shouldn't affect the appearance of your control since this textbox will be hidden, the enter should work correctly, this is an IE issue

Edit: Ignore this if you use .NET 2.0 which introduced defaultButton

Try this:

<form id="form1" runat="server" defaultbutton="myButton">

Page.Form.DefaultButton - msdn link here

Just a small note: You cannot use the 'defaultButton' attribute if your button is a LinkButton, it doesn't work for that, taken from here: http://msdn.microsoft.com/en-us/library/system.web.ui.htmlcontrols.htmlform.defaultbutton.aspx

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!