如何实现按回车键提交webpart?

commandolee 2011-01-28 02:23:42
对于很多表单,在提交的时候如果能通过按回车来postback是很方便的。但是由于webpart与webform的机制不同,似乎无法直接在webpart中设置默认按钮来提交。

有没有人成功地实现过在webpart中将回车键按下的事件提交呢,谢谢
...全文
56 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
commandolee 2011-01-31
  • 打赏
  • 举报
回复
我找到了更好的解决办法:

"ASP.NET 2.0 makes this problems easier and introduce a concept of a "default button". New defaultbutton attribute can be used with <form> or <asp:panel> control. What button will be "clicked" depends of where actually cursor is and what button is chosen as a default button for form or a panel.

Here is sample HTML code that contains one form and one panel control:"

<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>
风影极光 2011-01-28
  • 打赏
  • 举报
回复
使用js捕捉键盘的enter事件即可。

3,242

社区成员

发帖
与我相关
我的任务
社区描述
企业开发 SharePoint
社区管理员
  • SharePoint社区
  • 霖雨
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧