【问题标题】:Issues with bootstrap popover and asp:button引导弹出框和 asp:button 的问题
【发布时间】:2017-01-27 04:07:25
【问题描述】:

我想在几页中通过 bootstrap popover 替换 js windows,但我有两个问题,我没有找到任何解决方案。

首先,如果我单击按钮以显示弹出框,则会直接触发必填字段。即使我填写了它,“xx 是必填字段”的消息仍然显示。

其次,当我尝试保存数据时。每个字段都包含一个额外的字符“,”。因此,如果我在我的字段值后面的代码中的价格字段中输入 10,则为“10”,

感谢您的帮助:)

我的代码:

<asp:Button ID="btnAdd" runat="server" Text="add" CssClass="btn btn-info"data-toggle="popover" data-placement="top" title="add something" ValidationGroup="vgAdd" />

<div id="testBox" class="hide">
   <asp:ValidationSummary ID="vsTest" runat="server" ValidationGroup="vgAdd" DisplayMode="BulletList" ShowMessageBox="false" ShowSummary="false" />
                                        <div class="row">
                                            <div class="form-group col-sm-6">
                                                <asp:Label ID="lblPrice" runat="server" Text="price" AssociatedControlID="txtPrice" CssClass="control-label"></asp:Label>
                                                <div class="input-group">
                                                    <span class="input-group-addon">$</span>
                                                    <asp:TextBox ID="txtPrice" runat="server" CssClass="form-control" MaxLength="12"></asp:TextBox>
                                                </div>
                                                <asp:CompareValidator ID="cvPrice1" runat="server" Display="None" ValidationGroup="vgAdd" ControlToValidate="txtPrice"
                                                    ErrorMessage="price is invalid." ValueToCompare="0" Type="Double" Operator="GreaterThan"></asp:CompareValidator>
                                                <asp:CompareValidator ID="cvPrice" runat="server" Display="None" ValidationGroup="vgAdd" ControlToValidate="txtPrice"
                                                    Type="Double" Operator="DataTypeCheck" ErrorMessage="price is invalid."></asp:CompareValidator>
                                                <asp:RequiredFieldValidator runat="server" ID="RequiredFieldValidator1" ValidationGroup="vgAdd" ControlToValidate="txtPrice"
                                                    ErrorMessage="Default price is a required field." SetFocusOnError="True" Display="Dynamic" />
                                            </div>
                                            <div class="form-group col-sm-6">
                                                    <asp:Label ID="lblDesc" runat="server" Text="Description" AssociatedControlID="txtDesc" CssClass="control-label"></asp:Label>
                                                    <asp:TextBox ID="txtDesc" runat="server" CssClass="form-control" TextMode="MultiLine" MaxLength="255"></asp:TextBox>
                                                </div>
                                        </div>
                                        <div class="clearfix">
                                            <asp:Button ID="btnSave" runat="server" ValidationGroup="vgAdd" CausesValidation="true"
                                                CssClass="btn btn-primary pull-right"
                                                OnClick="btnSaveTest_Click" Text="Save" />
                                        </div>
                                    </div>

$("[data-toggle=popover]").popover({
        html: true,
        content: function () {
            return $('#testBox').html();
        }
    });

【问题讨论】:

    标签: css asp.net twitter-bootstrap webforms bootstrap-popover


    【解决方案1】:

    要解决第一个问题,您需要从#btnAdd 中删除ValidationGroup="vgAdd";您不想在单击此按钮时验证表单。

    关于第二个 - 您的 html 代码中没有可以附加逗号的内容。您必须在后端代码或 javascript 中有一些东西。我建议您从单击按钮 #btnSave 的那一刻开始一直调试 - 首先是 javascript,然后是后面的代码。

    【讨论】:

    • 谢谢墨菲斯。我删除了 ValidationGroup 所以现在弹出框不会触发所需的字段。但是如果该字段为空并且我想提交表单,则不会显示该消息。仅关注该字段,但消息“默认价格是必填字段”。不显示在字段下方。仅当弹出框关闭并再次打开时才会显示。关于我所有领域中的额外字符“,”我没有找到解决方案。如果我使用数据内容而不是选项内容,我没有任何问题。我尝试使用模板但同样的问题。真的很奇怪。
    • 当您将内容附加到弹出窗口时,id testBox 的 div 将从原始位置删除,因此验证器不会触发。从记忆中,我认为您需要在单击按钮时调用$('#testBox').detach()。设置内容,你试过content: $('#testBox').html()吗?
    • 其实我最大的问题是,如果我使用#testBox来显示我的内容,我会根据显示框的方式有两种不同的结果。如果按钮使用 JS 创建弹出窗口,一切都很好,但如果按钮使用弹出窗口,当我在代码后面时,我仍然在每个字段的末尾添加一个逗号。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-07-17
    • 2020-02-13
    • 1970-01-01
    • 2014-04-13
    • 1970-01-01
    • 2015-10-16
    • 1970-01-01
    相关资源
    最近更新 更多