How to hide modal pop up on browser back button

2019-08-08 17:52发布

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();
        }

    }

}

2条回答
家丑人穷心不美
2楼-- · 2019-08-08 18:17

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

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

查看更多
甜甜的少女心
3楼-- · 2019-08-08 18:21

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.

查看更多
登录 后发表回答