【问题标题】:Pressing enter in modal closes the modal but does not submit the data在模态中按回车键关闭模态但不提交数据
【发布时间】:2019-08-18 16:48:14
【问题描述】:

我正在使用 asp.net 网络表单和 bootstrap 3 我遇到的问题是当按下回车键时,将密码字段集中在关闭模式,但没有提交数据。

看到其他人有类似的问题,但他们的模式中的元素不同,例如,我的代码中有 asp:button,而其他可以让它工作的人则使用 input type="submit"。

<div class="modal fade borderless" id="reviewSign" tabindex="-1" role="dialog">
            <div class="modal-dialog" role="document">
                <div class="modal-content">
                    <div class="modal-header">
                        <a class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></a>
                        <h4 class="modal-title">You are about to review document:
                            <asp:Label ID="lblReviewSignDocName" runat="server" Text=""></asp:Label>
                            <asp:Label ID="lblReviewSignDocNr" runat="server" Text=""></asp:Label>
                        </h4>
                    </div>
                    <div class="modal-body">
                        <h5>Enter credentials and press "Ok" to review</h5>
                        <br />
                        <table>
                            <tbody>
                                <tr>
                                    <td>Username: </td>
                                    <td>
                                        <asp:TextBox ID="txtUserForReview" Class="form-control" Placeholder="Login Credentials" runat="server"></asp:TextBox></td>
                                </tr>
                                <tr>
                                    <td>Password: </td>
                                    <td>
                                        <asp:TextBox ID="txtPasswordForReview" Class="form-control" Placeholder="Password" TextMode="Password" runat="server"></asp:TextBox></td>
                                </tr>
                            </tbody>
                        </table>
                        <div runat="server" id="LNoteReviewSignDiv" visible="false">
                            <br />
                            <asp:Label ID="LNoteReviewSign" ForeColor="Red" runat="server"></asp:Label>
                            <br />
                        </div>
                    </div>
                    <div class="modal-footer">
                        <asp:Button runat="server" CssClass="btn btn-primary" Text="Ok" ID="btnReviewSign" OnClick="btnReviewSign_Click" />
                        <a class="btn btn-default" data-dismiss="modal">Cancel</a>
                    </div>
                </div>
            </div>
            <script type='text/javascript'>
                function openmodalReviewSign() {
                    $('[id=reviewSign]').modal('show');
                    $("#<%=txtPasswordForReview.ClientID %>").focus(200);
                }
            </script>
        </div>

预期的是,在密码字段集中时按 Enter 与按签名按钮的效果相同。另一个输入字段从后面的代码中设置为只读,因此无法聚焦。

或者,如果无法通过按 Enter 提交,我宁愿在按 Enter 时什么也不发生。

【问题讨论】:

  • 使用 LinkBut​​ton 而不是 Button 控件。然后它将起作用。见stackoverflow.com/a/41707237/5836671
  • asp:Panel 中包装输入和按钮并设置DefaultButton="btnReviewSign"

标签: asp.net twitter-bootstrap-3 webforms


【解决方案1】:

正如@AlexKudryashev 所建议的,将所有输入和按钮包装在一个 asp:Panel 中并设置 DefaultButton="btnReviewSign" 解决了这个问题。

请记住,只有在您使用 .net webforms 编写您的网站时,这才能解决此问题。

【讨论】:

    猜你喜欢
    • 2018-12-18
    • 1970-01-01
    • 2016-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-06-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多