Why is Page_Load not firing after coming back from another page using ASP.NET - ergo epic embarrassment :)

前端 未结 7 1819
故里飘歌
故里飘歌 2021-02-14 22:15

Let\'s say I have two pages on the same ASP.NET C# WebSite.

  • Page1.aspx does things in the Page_Load event
  • I navigate to Page2.aspx using the menu
7条回答
  •  南旧
    南旧 (楼主)
    2021-02-14 23:08

    I had the same problem and found that this works for me: (add this on the Page_Load section)

        if (this.Master.Page.Header != null && Session["RELOAD"] == null)
        {
            System.Web.UI.HtmlControls.HtmlHead hh = this.Master.Page.Header;
            System.Web.UI.HtmlControls.HtmlMeta hm = new System.Web.UI.HtmlControls.HtmlMeta();
            hm.Attributes.Add("http-equiv", "Refresh");
            hm.Attributes.Add("content", "3");
            hh.Controls.Add(hm);
        }
    

    and then I add Session["RELOAD"] = "1" right after it executes the code I want to run to prevent it from refreshing over and over again. Works like a charm.

提交回复
热议问题