开发者

ModalPopupExtender shows popup when the user hits the back button

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>
<Tri开发者_运维知识库ggers>
    <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?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜