兩種寫法:
1.javascript dopostback
<div id="divPanel">
<asp:TextBox ID="txbContent" runat="server" Width="60%" />
<asp:LinkButton ID="butAdd" runat="server" Text="新增" OnClick="butAdd_Click" />
</div>
<script type="text/javascript">
$(document).keypress(function (e) {
if ($('#divPanel').is(":visible") && e.which == 13) {
__doPostBack('<%=butAdd.UniqueID%>', "");
}
});
</script>
UniqueID詳細說明:
2.panel
用panel將要的元件包起來
並設定好defaultbutton屬性為Enter鍵後執行的buttonID
ex:
<asp:Panel ID="pAdd" runat="server" DefaultButton="butAdd">
<asp:TextBox ID="txbContent" runat="server" Width="60%" />
<asp:LinkButton ID="butAdd" runat="server" Text="新增" OnClick="butAdd_Click" />
</div>
</asp:Panel>
參考:
沒有留言:
張貼留言