当用户点击后退按钮时,ModalPopupExtender 显示弹出窗口
当用户通过浏览器的后退按钮导航到页面时,如何阻止 ModalPopupExtender 显示弹出窗口?
我尝试实现此处找到的解决方案,该解决方案本质上使用客户端脚本处理 ModalPopup但在实施时遇到了麻烦。 ($find("modPop") 始终返回 null)。
还有其他技术可以处理这个问题吗?
编辑:情节变厚。这只发生是因为我在弹出窗口内使用了 UpdatePanel。下面的代码应该会重复该错误。另请注意,需要使用虚拟按钮。
- 单击按钮显示模态
- 确认模
- 态 离开页面
- 使用后退按钮导航回页面
- 模态出现不良。
<%@ 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.
- Click button to show modal
- Confirm modal
- Navigate away from page
- Navigate back to page w/ back button
- 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在 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 bempTest
. Try explicitly settingBehaviorId="mpTest"
on yourModalPopupExtender
as well and see if it works.