如何 return 到上一个搜索页面而不被要求确认重新提交表单并将结果保留在 ASP.NET 使用 c# 的经典 Web 表单上?

How to return to previous search page without being asked to Confirm Form Re-submission and keeping the results on ASP.NET classic Web-forms with c#?

我正在为学校做一个项目,这个页面有一些搜索结果。 当我返回搜索结果页面时,浏览器要求 "Confirm Form Re-submission",我想避免这种情况。

到目前为止,除了在网上搜索解决方案之外,我没有采取任何措施来解决这个问题,而且还没有找到。

浏览器消息: 确认重新提交表单 此网页需要您之前输入的数据才能正确显示。您可以再次发送此数据,但这样做会重复此页面之前执行的任何操作。 按重新加载按钮重新提交加载页面所需的数据。 ERR_CACHE_MISS

问题在于你正在做一个 post 请求,如果使用你的网页的人刷新它,它做了它应该做的事情 重新提交 post 请求.

因此,无法阻止此问题的发生,您可以做的是改变从 post 请求获取值的方式以获取请求。

你好。找到了我的问题的解决方案。

所以我所做的是,将值存储在会话中,重定向到循环页面并返回,然后在加载表单时执行搜索。现在我可以毫无问题地来回走动了。这是我使用的代码:

搜索页面:

protected void btnSearch_Click(object sender, EventArgs e) 
{ 
   Session["searchValue"] = txtSearchValue.Text; 
   Response.Redirect("loopPage.aspx"); 
} 

LoopPage.aspx 上的代码:

protected void Page_Load(object sender, EventArgs e)
{ 
   Response.Redirect("searchPage.aspx"); 
} 

再次搜索页面:

protected void Page_Load(object sender, EventArgs e) 
{ 
   if (Session["searchValue"] != null) 
   { 
      ...preform search and create objects to present results...
   } 
}