当用户点击后退按钮时,ModalPopupExtender 显示弹出窗口

发布于 2024-10-04 01:14:07 字数 1981 浏览 3 评论 0原文

当用户通过浏览器的后退按钮导航到页面时,如何阻止 ModalPopupExtender 显示弹出窗口?

我尝试实现此处找到的解决方案,该解决方案本质上使用客户端脚本处理 ModalPopup但在实施时遇到了麻烦。 ($find("modPop") 始终返回 null)。

还有其他技术可以处理这个问题吗?

编辑:情节变厚。这只发生是因为我在弹出窗口内使用了 UpdatePanel。下面的代码应该会重复该错误。另请注意,需要使用虚拟按钮。

  1. 单击按钮显示模态
  2. 确认模
  3. 态 离开页面
  4. 使用后退按钮导航回页面
  5. 模态出现不良。
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Test.aspx.vb" Inherits="Test" %>
<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server" EnablePartialRendering="true"> </asp:ScriptManager>

<span style="display:none;"><asp:Button ID="btnDummy" runat="server" Text="Dummy" /></span>
<asp:Button id="btnShow" runat="server" Text="Show Modal"/>
<ajax:ModalPopupExtender ID="mpTest" runat="server" TargetControlID="btnDummy" PopupControlID="pnlTest"></ajax:ModalPopupExtender>
<asp:Panel id="pnlTest" style="display:none;border:10px solid green" DefaultButton="btnTest" runat="server">        
<asp:UpdatePanel ID="upTest" runat="server">
<ContentTemplate>
        <asp:Button ID="btnTest" runat="server" Text="Test" />        
</ContentTemplate>
<Triggers>
    <ajax:AsyncPostBackTrigger ControlID="btnTest" />
</Triggers>
</asp:UpdatePanel>
</asp:Panel>
<a href="http://stackoverflow.com">StackOverflow</a>
</div>
</form>
Partial Class Test
    Inherits System.Web.UI.Page

    Protected Sub btnShow_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnShow.Click
        mpTest.Show()
    End Sub

    Protected Sub btnTest_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnTest.Click
        mpTest.Hide()
    End Sub

End Class

我认为这是有道理的,因为当您确认模式时,不会发生完整的回发,但我需要这样做。有什么解决方法吗?

How do I stop a ModalPopupExtender from showing the popup when a user navigates to the page via the browser's back button?

I tried to implement the solution found here which essentially handles the ModalPopup using client side script but had trouble with its implementation. ($find("modPop") always returns null).

Are there other techniques for handling this?

EDIT: The plot thickens. This only occurs because I am using an UpdatePanel inside of the popup. The code below should duplicate the error. Also note, the use of the dummy button is required.

  1. Click button to show modal
  2. Confirm modal
  3. Navigate away from page
  4. Navigate back to page w/ back button
  5. Modal appears undesireably.
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Test.aspx.vb" Inherits="Test" %>
<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server" EnablePartialRendering="true"> </asp:ScriptManager>

<span style="display:none;"><asp:Button ID="btnDummy" runat="server" Text="Dummy" /></span>
<asp:Button id="btnShow" runat="server" Text="Show Modal"/>
<ajax:ModalPopupExtender ID="mpTest" runat="server" TargetControlID="btnDummy" PopupControlID="pnlTest"></ajax:ModalPopupExtender>
<asp:Panel id="pnlTest" style="display:none;border:10px solid green" DefaultButton="btnTest" runat="server">        
<asp:UpdatePanel ID="upTest" runat="server">
<ContentTemplate>
        <asp:Button ID="btnTest" runat="server" Text="Test" />        
</ContentTemplate>
<Triggers>
    <ajax:AsyncPostBackTrigger ControlID="btnTest" />
</Triggers>
</asp:UpdatePanel>
</asp:Panel>
<a href="http://stackoverflow.com">StackOverflow</a>
</div>
</form>
Partial Class Test
    Inherits System.Web.UI.Page

    Protected Sub btnShow_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnShow.Click
        mpTest.Show()
    End Sub

    Protected Sub btnTest_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnTest.Click
        mpTest.Hide()
    End Sub

End Class

I think this makes sense as when you confirm the modal a full postback doesn't happen but I need to do it this way. Are there any workarounds?

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

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

发布评论

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

评论(1

随风而去 2024-10-11 01:14:07

在 ASP.NET 论坛的解决方案中,$find("modPop") 中的 modPop 是模式弹出窗口的行为 id,在您的情况下将是 mp测试。尝试在您的 ModalPopupExtender 上显式设置 BehaviorId="mpTest" 并查看它是否有效。

In the solution on the ASP.NET forum, the modPop in $find("modPop") is the behavior id of the modal popup which in your case will be mpTest. Try explicitly setting BehaviorId="mpTest" on your ModalPopupExtender as well and see if it works.

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