防止在asp:textbox上的模式关闭

时间:2019-07-11 09:26:27

标签: c# asp.net

在模态asp文本框中输入key enter时,我试图防止模态关闭。

我试图将文本框包装在另一个更新面板中,并在textchanged上使用异步回发触发器,但这并不是我想要的。我正在尝试创建一个文本输入部分,该部分仅在按下Enter键时更新,而在文本更改时不更新,我还尝试像其他页面建议的那样向文本框本身添加data-dismiss =“ modal”,但这仅意味着当我单击文本框时,它会关闭模式。

<asp:UpdatePanel ID="upd_mdl_console" runat="server" UpdateMode="Conditional">
    <ContentTemplate>
        <!-- Ryan Console-->
        <div class="modal fade" data-dismiss="modal" data-toggle="modal" data-backdrop="static" data-keyboard="false" id="mdl_console" tabindex="-1" role="dialog">
            <div class="modal-dialog2" role="document">
                <div class="modal-content _dev_console">
                    <div class="modal-header _dev_console">
                        <h5 class="modal-title pull-left" id="H1" runat="server">
                            <asp:Label runat="server" ID="Label3" Text="DEV CONSOLE"></asp:Label></h5>
                        <button type="button" class="close pull-right" data-dismiss="modal" aria-label="Close">
                            <span aria-hidden="true">&times;</span>
                        </button>
                        <br />
                    </div>
                    <div class="modal-body">
                        <div class="panel-heading _dev_console">
                            <asp:Literal ID="devbox_line_5" runat="server" Text=""></asp:Literal>
                            <asp:Literal ID="devbox_line_4" runat="server" Text=""></asp:Literal>
                            <asp:Literal ID="devbox_line_3" runat="server" Text=""></asp:Literal>
                            <asp:Literal ID="devbox_line_2" runat="server" Text=""></asp:Literal>
                            <asp:Literal ID="devbox_line_1" runat="server" Text=""></asp:Literal>
                            <asp:UpdatePanel ID="upd_mdl_txt" runat="server" UpdateMode="Conditional">
                                <ContentTemplate>
                                    <asp:TextBox ID="txt_Devbox" class="form-control _dev_console" runat="server" autocomplete="off"></asp:TextBox>
                                </ContentTemplate>
                            </asp:UpdatePanel>

                        </div>
                        <div class="panel-heading _dev_console">
                            <div class="input-group" style="margin-bottom: 10px; width: 100%">
                            </div>
                        </div>
                    </div>
                    <div style="clear: both"></div>
                    <div class="modal-footer _dev_console">
                        <asp:Label ID="Label4" runat="server" Text="Label" Visible="false"></asp:Label>
                        <%--                            <asp:Button ID="Button1" OnClick="lnk_go_Click" class="btn btn-success" runat="server" AutoPostBack="false" Text="Create"></asp:Button>--%>
                        <button type="button" class="btn btn-secondary _dev_console" data-dismiss="modal">Close</button>
                    </div>
                </div>
            </div>
        </div>
    </ContentTemplate>
</asp:UpdatePanel>

1 个答案:

答案 0 :(得分:1)

我使用以下代码段禁止在文本框中输入。当在文本框中按Enter时,这还可以防止触发表单发布。可能也可以防止模式的关闭。

$('input').keypress(function (e) {
    return e.keyCode !== 13;
});

如果只想禁用模式中的回车,则可以执行以下操作

$('.modal-body input').keypress(function (e) {
    return e.keyCode !== 13;
});