页面后退时如何运行Page_Load [英] How to run Page_Load when page backs
本文介绍了页面后退时如何运行Page_Load的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
你好,
我在Page_Load(object sender,EventArgs e)中有一个生成一些动态html代码的方法.
将页面导航到另一个页面后,当我单击IE的后退按钮时,将没有生成的html.问题是Page_Load不再运行.
我该如何解决这个问题.
Hello,
I have a method in Page_Load(object sender, EventArgs e) that generates some dynamic html codes.
After navigating the page to another page, When I click the back button of my IE, I wont have my generated html. The problem is Page_Load doesn''t run again.
How can I solve this problem.
protected void Page_Load(object sender, EventArgs e)
{
CreateHTMLControls();
}
推荐答案
将此代码放在Page_Load事件中:
Hi,
Place this code in Page_Load event:
Response.CacheControl = "no-cache";
Response.AddHeader("Pragma", "no-cache");
Response.Expires = -1;
问候
Joachim
Regards
Joachim
执行页面的原因并不影响页面周期,在执行页面时始终会触发Load事件.
因此,如果Page_Load有时不运行,那是因为页面已缓存并且不在服务器上执行.可以将页面缓存在浏览器中,途中某处的路由器中,或者使用服务器端页面缓存在服务器上缓存
尝试禁用输出缓存,看看问题是否仍然出现:
The reason for the page executing doesn''t affect the page cycle, the Load event always fires when the page is executed.
So, if the Page_Load doesn''t run sometimes, it is because the page is cached and doesnt execute on the server. The page can be cached in the browser, in a router somewhere along the way, or on the server using server side page caching
Try disabling output cache and see if the problem still occurs:
<system.web>
<caching>
<outputCache enableOutputCache="false"/>
</caching>
<system.web>
作为替代方案,在Page_Load方法中添加以下代码以保留后退操作的内容.
As an alternative, add the below code in Page_Load method to retain the content on back operation.
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);
}
这篇关于页面后退时如何运行Page_Load的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文