I have 3 buttons in a form. One of them is the submit button. How can I make it the default button to be clicked when I press the enter key. Is there a property for this?
我在表单中有3个按钮。其中一个是提交按钮。当我按下回车键时,如何将其设为要单击的默认按钮。有这个属性吗?
3 个解决方案
#1
There is a property for the form: defaultbutton.
表单有一个属性:defaultbutton。
<form runat="server" defaultbutton="myButton">
...
</form>
It is first time implemented in ASP.NET 2.0.
它是第一次在ASP.NET 2.0中实现。
#2
Another helpful tip is that you can set the default button on asp:panel's too.
另一个有用的提示是你可以在asp:panel上设置默认按钮。
#3
Or you can do it in code - Page_load:
或者您可以在代码中执行此操作 - Page_load:
Page.Form.DefaultButton = btnSearch.UniqueID;
Whenever you press enter the btnSearch control will be used as default.
每当您按Enter键时,btnSearch控件将被用作默认值。
#1
There is a property for the form: defaultbutton.
表单有一个属性:defaultbutton。
<form runat="server" defaultbutton="myButton">
...
</form>
It is first time implemented in ASP.NET 2.0.
它是第一次在ASP.NET 2.0中实现。
#2
Another helpful tip is that you can set the default button on asp:panel's too.
另一个有用的提示是你可以在asp:panel上设置默认按钮。
#3
Or you can do it in code - Page_load:
或者您可以在代码中执行此操作 - Page_load:
Page.Form.DefaultButton = btnSearch.UniqueID;
Whenever you press enter the btnSearch control will be used as default.
每当您按Enter键时,btnSearch控件将被用作默认值。