弹出窗口不能正确加载.它需要每次刷新页面

Pop-up does not load correctly. It needs page refresh every time

本文关键字:刷新 窗口 不能 加载      更新时间:2023-09-26

有一个链接:

<div >
    <a href="#" class="newComment" onclick="bindAddSlots()">Add Details</a>
</div>

onclick方法:

 function bindAddSlots() {
     debugger;
     if (!CheckforLogout()) {
         return false;
     }
     ClearPopUpControls();
     var dclg;
     dclg = $("#dvSchedulingProfile").dialog(
     {
         resizable: false,
         draggable: true,
         modal: true,
         title: "ADD Details",
         width: "400",
         height: "460"
     });
     dclg.parent().appendTo(jQuery("form:first"));
}
function ClearPopUpControls() {
    debugger;
    $("#ddlVisitType").val("Select Options");
    $("#SchedulingProfileDetails_Id").val("0");
    $("#dvSchedulingProfile").find("#txtNP").val("");
    $("#dvSchedulingProfile").find("#txtNS").val("");
    $("#dvSchedulingProfile").find(".lblAnnualVisitType").hide();
    $("#dvSchedulingProfile").find(".lblNP").hide();
    $("#dvSchedulingProfile").find(".lblNS").hide();
    $("#dvSchedulingProfile").find(".lblNPNumeric").hide();
    $("#dvSchedulingProfile").find(".lblNSNumeric").hide();
    $("#SchedulingProfileDetails_Id").val("0");
}

视图代码:

<div id="dvSchedulingProfile" style="display: none">
        @Html.ValidationSummary(true)
        <table width="100%" height="75%" class="someclass">
             <tr id="AddVisitType">
                <td  class="black_label">
                    @Html.HiddenFor(m => m.SchedulingProfileDetails.Id)
                    @Html.Label("Visit Type"):<span class="star">*</span>
                </td>
                <td  style="font-size: 12px;">
                    @Html.DropDownList("ddlVisitType", new SelectList((VisitTypeBo.LoadAll().OrderBy(x => x.VisitTypeName)), "VisitTypeName", "VisitTypeName"), new { @style = "width:250px;color:black" })
                <br/>
                </td>
            </tr>
            <tr>
                <td height="5">
                </td>
                <td style="color: Red; font-size: 12px; display: none;" class="lblAnnualVisitType"
                    align="left">
                    @Html.Label("lblAnnualVisitType", "Visit Type is required.")
                </td>
            </tr>
            <tr>
                <td height="5">
                </td>
            </tr>
            <tr>
                <td class="black_label">
                    @Html.Label("Patient Slots(NP)"):<span class="star">*</span>
                </td>
                <td style="font-size: 12px;">
                    @Html.TextBox("txtNP", null, new { @style = "width:250px;", maxlength = 11 })
                </td>
            </tr>
            <tr>
                <td height="5">
                </td>
                <td style="color: Red; font-size: 12px; display: none;" class="lblNP" align="left">
                    @Html.Label("lblNP", "NP is required.")
                </td>
                <td style="color: Red; font-size: 12px; display: none;" class="lblNPNumeric" align="left">
                    @Html.Label("lblNPNumeric", "Only Numeric values are allowed.")
                </td>
            </tr>
            <tr>
                <td class="black_label">
                    @Html.Label("Time Slots(NS)"):<span class="star">*</span>
                </td>
                <td style="font-size: 12px;">
                    @Html.TextBox("txtNS", null, new { @style = "width:250px;", maxlength = 11 })
                </td>
            </tr>
            <tr>
                <td height="5">
                </td>
                <td style="color: Red; font-size: 12px; display: none;" class="lblNS" align="left">
                    @Html.Label("lblNS", "NS is required.")
                </td>
                <td style="color: Red; font-size: 12px; display: none;" class="lblNSNumeric" align="left">
                    @Html.Label("lblNSNumeric", "Only Numeric values are allowed.")
                </td>
            </tr>
            <tr>
                <td height="5">
                </td>
            </tr>
            <tr>
                <td>
                </td>
                <td >
                    <input type="button" value="" class="save_bt" onclick="return SaveDetails()" style="margin-left:70PX;"/>
                </td>
            </tr>
        </table>
    </div>

现在的问题是,当页面加载,我点击弹出窗口的链接,但弹出窗口出来了,我需要刷新代码,问题是相同的,在所有的浏览器。我一次又一次地调试代码,但没有错误的到来,我完全困惑,所以有人请帮助我克服这个问题。

究竟需要将对话框附加到表单的第一个元素上吗?如果你去掉那条线,我想应该没问题。

因为,第一次它工作正常,因为只有一个元素与id dvSchedulingProfile和立即显示对话框后,你添加相同的元素再次到表单的第一个元素,所以下次有两个元素具有相同的id,现在jquery对话框不工作,因为它不会找到一个单一的元素与给定的id..

问题是,当我们关闭对话框时,它只是关闭的,但我们需要销毁它,这样表单就没有任何剩余的关联。因此,我们需要一些额外的代码行来决定当我们关闭弹出窗口时要做什么。

var dclg=$("#dvSchedulingProfile")
     dclg.dialog(
     {
         resizable: false,
         draggable: true,
         modal: true,
         title: "ADD Details",
         width: "400",
         height: "460",
         close: function () {
          dclg.dialog("destroy");
          dclg.hide();
          }
     });