Chrome 后退按钮页面刷新 - ASP.net

发布于 2024-08-30 08:49:09 字数 997 浏览 7 评论 0原文

我有一个 ASP.net 应用程序(c#)。

当用户位于特定页面时,他们单击该页面上的链接,将其带到子页面,显示产品详细信息。

如果用户单击浏览器后退按钮,我需要将父页面刷新到其初始状态。即所有输入数据的文本框都需要为空,所有隐藏字段都需要重置等。基本上,当用户单击后退时,我需要 CTRL-F5。

禁用后退按钮不是一个选项。

我只在某些页面上需要这个。

在 IE 和 Firefox 中我可以毫无问题地完成此操作。但对于 chrome,文本框仍然包含它们的值,隐藏字段也是如此。如果我在 Chrome 中按 CTRL-F5,页面会正确重置为其初始状态。

这是我尝试过的代码。

<%@ OutputCache Location="None" VaryByParam="None" %>

和这个:

   Response.Buffer = true;
   Response.Cache.SetCacheability(HttpCacheability.NoCache);
   Response.Cache.SetAllowResponseInBrowserHistory(false);
   Response.Cache.SetNoStore();

和这个:

    Response.Cache.SetExpires(DateTime.UtcNow.AddDays(-1));
    Response.Cache.SetValidUntilExpires(false);
    Response.Cache.SetRevalidation(HttpCacheRevalidation.AllCaches);
    Response.Cache.SetCacheability(HttpCacheability.NoCache);
    Response.Cache.SetNoStore();

我也尝试过各种不同的组合,但没有成功。

谢谢

I have an ASP.net application (c#).

When a user is on a specific page, they click a link on this page that takes them to a child page, displaying the product details.

If the user clicks the browser back button, I need the parent page to be refreshed to its initial state. ie all text boxes that had data typed need to be blank, any hidden fields reset etc. Basically i need a CTRL-F5 when a user clicks back.

Disabling the back button is not an option.

I need this only on certain pages.

In IE and Firefox i can get this working without an issue. But with chrome the textboxes still contain their values as do the hidden fields. If I hit CTRL-F5 in Chrome, the page is correctly reset to its initial state.

This is the code I have tried.

<%@ OutputCache Location="None" VaryByParam="None" %>

and this:

   Response.Buffer = true;
   Response.Cache.SetCacheability(HttpCacheability.NoCache);
   Response.Cache.SetAllowResponseInBrowserHistory(false);
   Response.Cache.SetNoStore();

and this:

    Response.Cache.SetExpires(DateTime.UtcNow.AddDays(-1));
    Response.Cache.SetValidUntilExpires(false);
    Response.Cache.SetRevalidation(HttpCacheRevalidation.AllCaches);
    Response.Cache.SetCacheability(HttpCacheability.NoCache);
    Response.Cache.SetNoStore();

I have also tried a variety of these in different combination, but with no success.

thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

勿忘初心 2024-09-06 08:49:09

当按下浏览器的后退按钮时,浏览器不会自动重置输入字段。相反,浏览器会保留用户的输入,使用户更容易返回并更改输入。

您无法在服务器端解决此问题,因为浏览器会绕过缓存。相反,您可以在输入字段上使用 autocomplete="off" HTML 属性来防止浏览器保留它们。

您还可以使用 JavaScript 手动重置表单:

document.getElementById("form1").reset();

When the browser's back button is pressed, the INPUT fields are not reset automatically by the browser. Instead, the browser retains the user's input, making it easier for users to go back and make a change to the input.

You cannot solve this server-side, because the browser bypasses the cache for this. Instead, you can use the autocomplete="off" HTML attribute on the input fields to prevent them from being retained by the browser.

You can also manually reset the form using JavaScript:

document.getElementById("form1").reset();
很酷又爱笑 2024-09-06 08:49:09

这两行为我解决了 Chrome 问题:

Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.Cache.SetNoStore();

我使用此可选行告诉浏览器不要为同一页面的每个请求创建历史记录条目:

Response.Cache.SetAllowResponseInBrowserHistory(true);

Sources:

本文中最受欢迎的答案

可选线路

These two lines solved the Chrome problem for me:

Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.Cache.SetNoStore();

And I use this optional line to tell the browser not to create a history entry for each request of the same page:

Response.Cache.SetAllowResponseInBrowserHistory(true);

Sources:

Most popular answer in this post

Optional line

魄砕の薆 2024-09-06 08:49:09

“强力”解决方案是在页面上放置一些 JavaScript,在页面加载时将数据设置为某种已知状态。因此它会找到所有元素并根据数据数组或 json 对象设置数据。在最初的请求中,由于一切都是默认的,因此该设置不会产生任何影响。在后退按钮请求中,由于仍然需要运行 javascript,因此无论浏览器如何,它都会重置所有值。

我不相信你可以强迫浏览器按照你描述的方式运行,因为这取决于每个浏览器如何实现后退按钮 - chrome 只是做得不同。

The 'brute force' solution would be to put some javascript on the page that on page load sets the data to some known state. So it finds all the elements and sets the data based on an array of data or json object. On the initial request, since everything is defaulted anyways, the setting doesn't make a difference. On a back button request, since the javascript still has to be run, it resets all the values, regardless of browser.

I don't believe you can force a browser to function in the way you describe though, as it's up to each browser how they want to implement a back button - chrome just does it differently.

無心 2024-09-06 08:49:09

您还可以将 autocomplete="off" 放在表单标记上,而不是每个输入字段上。

You can also put the autocomplete="off" on the form tag instead of every input field.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文