防止 ModalPopupExtender 在 PostBack 期间/之后关闭 [英] Preventing ModalPopupExtender from closing during/after PostBack

查看:59
本文介绍了防止 ModalPopupExtender 在 PostBack 期间/之后关闭的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何防止我的 asp:ModalPopupExtender 在回发到服务器之后或期间关闭??

How do I prevent my asp:ModalPopupExtender from closing after or during a postback to the server??

这是我的代码:

JAVASCRIPT

// Confirm popup Ok button
function OnOk() {
    $('#confirmPopup').hide();
    ClickSaveButton();      // does a postback
    ShowGridPopup();
}

ASP.NET AJAX

    <asp:ModalPopupExtender BehaviorID="confirmPopup" ID="confirmPopup" runat="server"
        TargetControlID="butConfirm" PopupControlID="ConfirmView" BackgroundCssClass="modalBackground"
        OnOkScript="OnOk();" OnCancelScript="OnCancel();"
        OkControlID="yesButton" CancelControlID="noButton">
    </asp:ModalPopupExtender>

无论我在回发方法 ClickSaveButton() 之前或之后调用 ShowGridPopup(),弹出窗口仍然消失.我怎样才能防止这种情况?

No matter if I call ShowGridPopup() before or after the postback method ClickSaveButton(), the popup still dissapears. How can I prevent this?

编辑

这是 ShowGridPopup()ClickSaveButton()

function ShowGridPopup() {
    if (getID() == "Popup1") {
        ShowGridPopup1();
    } else if (getID() == "Popup2") {
        ShowGridPopup2();
    }
}

function ClickSaveButton() {
    var _id = $('a[id$="butSave"]').attr("ID");
    __doPostBack(_id.replace("_", "$"), '');
}

推荐答案

我找到了绕过这个的方法,这是我的解决方案:你必须从服务器创建一个新的 HiddenField 控制器-side 在 ASP 中将用于存储您要在回发后显示的 ModalPopupExtender 的 ID,如果没有要显示的弹出窗口,则设置为 null.

I have found a way to by pass this, here is my solution: You have to create a new HiddenField controller from the server-side in ASP that will be used to store the ID of the ModalPopupExtender that you want to show after postback, it is set to null if there is no popup to be shown.

<!-- Grid Popup ID: to obtain the grid popup ID from server-side -->
<asp:HiddenField id="gridPopupID" runat="server" value="" />

接下来,我们需要在使用保存事件之前将ID设置为HiddenField

Next, we need to set the ID to the HiddenField before we use the save event

// Confirm popup Ok button
function OnOk() {
    $('#confirmPopup').hide();                          // hides the current confirmation popup
    $("#<%= gridPopupID.ClientID %>").val(getID());     // set the ID to the hiddenField.
    ClickSaveButton();                                  // simulates the click of the save button
}

现在,在后面的代码中,我们需要做的就是检查 HiddenField 文本字段的值,我们可以在相应地更正弹出窗口.

Now, in the code behind, all we need to do is check the value of the HiddenField text field and we can just do a .Show() on the correct popup accordingly.

Protected Sub OnSaveAssociation(ByVal sender As Object, ByVal e As EventArgs) Handles butSaveAssociation.Click

' ommited code: save changes to back end

            ' determine which popup to show
            Dim _id As String = gridPopupID.Value
            Select Case _id
                Case "Popup1"
                    gridPopup1.Show()
                    gridPopupID.Value = Nothing
                Case "Popup2"
                    gridPopup2.Show()
                    gridPopupID.Value = Nothing
            End Select

End Sub

这篇关于防止 ModalPopupExtender 在 PostBack 期间/之后关闭的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆