以下代码在没有更新面板的情况下工作,但在有更新面板时不会运行。其目的是清除来自向后或向前浏览器按下的页面条目上的 bfcache。任何人都知道当用户返回/前进并且页面有更新面板时如何让 js 运行?
window.onpageshow = function (event) { if (event.persisted) { window.location.reload() } };
带有更新面板的完整页面:
<body>
<form id="form1" runat="server">
<ajaxToolkit:ToolkitScriptManager runat="server" ID="ToolkitScriptManager" />
<asp:UpdatePanel ID="updatePanel1" UpdateMode="Conditional" runat="server">
<ContentTemplate>
<script type="text/javascript">
var js = "window.onpageshow = function (event) { if (event.persisted) { window.location.reload() } };";
Sys.Application.add_load(js);
var prm = Sys.WebForms.PageRequestManager.getInstance();
prm.add_endRequest(js);
prm.add_beginRequest(js);
</script>
<a href='Default.aspx'>Default</a>
<a href='Default2.aspx'>Default2</a>
<a href='Default3.aspx'>Default3</a>
<a href='Default4.aspx'>Default4</a>
<br />
<div>
<asp:TextBox ID="tbText" runat="server"></asp:TextBox>
</div>
</ContentTemplate>
</asp:UpdatePanel>
</form>
尝试#2
<body>
<script type="text/javascript">
window.onpageshow = function (event) { if (event.persisted) { window.location.reload() } };
</script>
<form id="form1" runat="server">
<ajaxToolkit:ToolkitScriptManager runat="server" ID="ToolkitScriptManager" />
<asp:UpdatePanel ID="updatePanel1" UpdateMode="Conditional" runat="server">
<ContentTemplate>
<a href='Default.aspx'>Default</a>
<a href='Default2.aspx'>Default2</a>
<a href='Default3.aspx'>Default3</a>
<a href='Default4.aspx'>Default4</a>
<br />
<div>
<asp:TextBox ID="tbText" runat="server"></asp:TextBox>
</div>
</ContentTemplate>
</asp:UpdatePanel>
</form>
尝试#3
<body>
<form id="form1" runat="server">
<ajaxToolkit:ToolkitScriptManager runat="server" ID="ToolkitScriptManager" />
<asp:UpdatePanel ID="updatePanel1" UpdateMode="Conditional" runat="server">
<ContentTemplate>
<script type="text/javascript">
var js = window.onpageshow = function (event) { if (event.persisted) { window.location.reload() } };;
Sys.Application.add_load(js);
var prm = Sys.WebForms.PageRequestManager.getInstance();
prm.add_endRequest(js);
prm.add_beginRequest(js);
</script>
<a href='Default.aspx'>Default</a>
<a href='Default2.aspx'>Default2</a>
<a href='Default3.aspx'>Default3</a>
<a href='Default4.aspx'>Default4</a>
<br />
<div>
<asp:TextBox ID="tbText" runat="server"></asp:TextBox>
</div>
</ContentTemplate>
</asp:UpdatePanel>
</form>