如何将按钮设为默认按钮 [英] How to make button at as default button

查看:112
本文介绍了如何将按钮设为默认按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我想将按钮设置为默认按钮,我想在单击键盘上的Enter按钮时将其触发


提前发送

Hi
I want to make the button as default, i mean i want to fire it when i click enter button on key board


Tx in advance

推荐答案

尝试一下.
Try this.
<form id="form1" runat="server" defaultbutton="Button1"></form>




如果要有多个默认按钮(例如,在同一页面上有一个搜索按钮和一个联系表单),则可以按以下方式使用它:

Hi,

If you want to have multiple default buttons (for example you have a search-button and a contact form on the same page), you could use it this way:

<form runat="server">
	<asp:Panel runat="server" DefaultButton="btnSearch">
		<asp:TextBox ID="tbSearchText" runat="server" />
		<asp:Button ID="btnSearch" runat="server" Text="Search" />
	</asp:Panel>

	<asp:Panel runat="server" DefaultButton="btnSendContact">
		<asp:TextBox ID="tbFirstname" runat="server" />
		<asp:TextBox ID="tbLastname" runat="server" />
		<asp:TextBox ID="tbComment" runat="server" />
		<asp:Button ID="btnSendContact" runat="server" Text="Submit" />
	</asp:Panel>
</form>



在某些服务器控件周围使用面板将呈现div HTML标签,并添加一些JavaScript,以允许默认按钮触发.

如果您问自己为什么必须使用它,那就很简单:由于ASP.NET仅允许一个form HTML标记,因此您无法在一页上创建多个表单,因此您不能在每个页面上使用默认按钮的HTML功能.表单(因为浏览器只会触发它在页面上找到的第一个按钮).

希望这会有所帮助.


致以诚挚的问候,祝您编程愉快,
克里斯



Using a panel around some server-controls renders a div HTML tag and adds some JavaScript which allows the default-button firing.

If you ask yourself why you have to use this, thats simple: because ASP.NET only allows one form HTML tag, you cannot create multiple forms on one page, so you cannot use the HTML feature of the default button firing on each form (because the browser would just fire the first button it finds on the page).

Hope this helps.


Best regards and happy coding,
Chris


这篇关于如何将按钮设为默认按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆