防止 ModalPopupExtender 在回发期间/之后关闭

发布于 2024-11-10 07:36:37 字数 1211 浏览 3 评论 0原文

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

这是我的代码:

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>

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

编辑

这是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("_", "$"), '');
}

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

Here is my code:

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>

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

EDIT

Here is the code for the ShowGridPopup() and ClickSaveButton()

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

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

痞味浪人 2024-11-17 07:36:37

您应该使用 UpdatePanel,这样 ModalPopupExtender 在回发后就不会隐藏。请参阅下面的示例:

Aspx:

<body> 
    <form id="form1" runat="server"> 
    <asp:ScriptManager ID="ScriptManager1" runat="server"> 
    </asp:ScriptManager> 
    <div> 
        <asp:UpdatePanel ID="udpOutterUpdatePanel" runat="server"> 
             <ContentTemplate> 

                 <asp:Button ID="ButtonShow" runat="server" Text="Show Popup" OnClick="ButtonShow_Click" />                 


                <input id="dummy" type="button" style="display: none" runat="server" /> 
                <ajaxToolkit:ModalPopupExtender runat="server" 
                        ID="mpeThePopup" 
                        TargetControlID="dummy" 
                        PopupControlID="pnlModalPopUpPanel" 
                        BackgroundCssClass="modalBackground"                        
                        DropShadow="true"/>
                 <asp:Panel ID="pnlModalPopUpPanel" runat="server" CssClass="modalPopup"> 
                    <asp:UpdatePanel ID="udpInnerUpdatePanel" runat="Server" UpdateMode="Conditional"> 
                        <ContentTemplate> 
                            Message
                            <asp:Button ID="ButtonClose" runat="server" Text="Close Popup" OnClick="ButtonClose_Click" />                                                                  
                        </ContentTemplate>       
                    </asp:UpdatePanel> 
                 </asp:Panel> 

            </ContentTemplate> 
        </asp:UpdatePanel> 
    </div> 
    </form> 
</body>

代码隐藏:

    protected void ButtonShow_Click(object sender, EventArgs e)
    {
        //Show ModalPopup               

        mpeThePopup.Show(); 
    }
    protected void ButtonClose_Click(object sender, EventArgs e)
    {
        //Hide ModalPopup

        mpeThePopup.Hide();
    }

You should use UpdatePanel, so the ModalPopupExtender won't be hidden after postback. See this example below :

Aspx:

<body> 
    <form id="form1" runat="server"> 
    <asp:ScriptManager ID="ScriptManager1" runat="server"> 
    </asp:ScriptManager> 
    <div> 
        <asp:UpdatePanel ID="udpOutterUpdatePanel" runat="server"> 
             <ContentTemplate> 

                 <asp:Button ID="ButtonShow" runat="server" Text="Show Popup" OnClick="ButtonShow_Click" />                 


                <input id="dummy" type="button" style="display: none" runat="server" /> 
                <ajaxToolkit:ModalPopupExtender runat="server" 
                        ID="mpeThePopup" 
                        TargetControlID="dummy" 
                        PopupControlID="pnlModalPopUpPanel" 
                        BackgroundCssClass="modalBackground"                        
                        DropShadow="true"/>
                 <asp:Panel ID="pnlModalPopUpPanel" runat="server" CssClass="modalPopup"> 
                    <asp:UpdatePanel ID="udpInnerUpdatePanel" runat="Server" UpdateMode="Conditional"> 
                        <ContentTemplate> 
                            Message
                            <asp:Button ID="ButtonClose" runat="server" Text="Close Popup" OnClick="ButtonClose_Click" />                                                                  
                        </ContentTemplate>       
                    </asp:UpdatePanel> 
                 </asp:Panel> 

            </ContentTemplate> 
        </asp:UpdatePanel> 
    </div> 
    </form> 
</body>

Code behind :

    protected void ButtonShow_Click(object sender, EventArgs e)
    {
        //Show ModalPopup               

        mpeThePopup.Show(); 
    }
    protected void ButtonClose_Click(object sender, EventArgs e)
    {
        //Hide ModalPopup

        mpeThePopup.Hide();
    }
寂寞笑我太脆弱 2024-11-17 07:36:37

将 ModalPopupExtender1.Show() 与更新面板一起使用以避免整个页面刷新。这对我来说非常有效。

Use, ModalPopupExtender1.Show() with update panel to avoid the whole page refresh. This has worked perfectly for me.

只为守护你 2024-11-17 07:36:37

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

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

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

// 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 的值文本字段,我们可以相应地在正确的弹出窗口上执行 .Show()

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

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="" />

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
}

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文