How to hide modal pop up on browser back button

戏子无情 提交于 2019-12-11 04:42:15

问题


I have an application where I will show Modal Popup on successful insert, update and delete. But after performing this when I move to next page and coming back to previous page on hitting browser back button the Modal Popup is getting displayed, I don't want to display this pop up on hitting back button. How can I solve this

protected void Page_Load(object sender, EventArgs e)
{
   if (Page.PreviousPage==null) {mpeModalPopup.Show(); }
    if (Session["Tasks"] == null)
    {
        Server.Transfer("login.aspx");
    }

    else
    {
        string strTasks = Session["Tasks"].ToString();
        if (strTasks.Contains("205"))
        {


            if (!IsPostBack)
            {
                mpeModalPopUp.Hide();
                funPageLoadData();
                CheckPopup();
                Session["url"] = System.Web.HttpContext.Current.Request.Url.AbsolutePath;
            }

        }
        else
        {
            ReturnBack();
        }

    }

}

回答1:


You dont seem to have handled Page.IsPostBack boolean property on your page_load event.

if (Page.PreviousPage==null) {mpeModalPopup.Show(); }




回答2:


For opening the popup (after postback) asp.net changes the html or inserts a javascript function to show the modal popup.

The only solution I know of is triggering an ajax postback (with an UpdatePanel) instead of a full postback when you click the button(s). This way the popup is loaded by an ajax call and won't display when you press the backbutton later on.



来源:https://stackoverflow.com/questions/9619595/how-to-hide-modal-pop-up-on-browser-back-button

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!