简体   繁体   English

刷新页面,无需重新发送POST数据(ASP.NET)

[英]Refresh a page, without resending POST data(ASP.NET)

How to refresh and reload the page without resending the POST data? 如何在不重新发送POST数据的情况下刷新和重新加载页面?

I have tried location.reload() which works absolutely fine on Chrome(which was the testing environment while development). 我试过了location.reload() ,它在Chrome上运行得非常好(这是开发时的测试环境)。 But IE and Firefox went into an Infinite Loop in JS - reposting a lot of junk/duplicate data. 但是IE和Firefox在JS中进入了无限循环 - 重新发布了大量垃圾/重复数据。

Note: However, I just want to refresh the page to clear all the form contents. 注意:但是,我只想刷新页面以清除所有表单内容。 I am also registering a start up script after Submit, that will show the alert message that data was added successfully. 我还在提交后注册了一个启动脚本,它将显示数据已成功添加的警报消息。

HELP! 救命!

试试这个:

window.location.href = window.location.href;
location.href = location.href + '?' + Math.random();

这应该工作。

在您的代码中添加:

Response.Redirect(Request.RawUrl)

If you just want to clear the form, why not: 如果您只想清除表单,为什么不:

<input type="reset" value="Clear Fields">

You could also do it using: 你也可以使用:

document.getElementById('<%=form1.ClientID%>').reset();

Seems a waste to reload the page unless you need to do something else as well. 除非你还需要做其他事情,否则看起来很浪费重新加载页面。

添加以下内容:

Server.Transfer(Request.RawUrl);

以下将解决您的问题:

Server.Transfer(Request.RawUrl);

use location.reload(true) . 使用location.reload(true) This "hard" reloads the page .. 这个“硬”重新加载页面..

I've try reload too, and reload(true) both not exactly doing what I wanted. 我也尝试重新加载,并重新加载(true)两者都没有完全做我想要的。

I've seen that Location Object have other method (than reload) since I wanted to request the page in "get" I just did: 我已经看到Location Object有其他方法(而不是重新加载)因为我想在“get”中请求页面我刚刚做了:

location.assign(window.location); 

So far seem to be doing what I want, reload the same page without submitting again values. 到目前为止似乎正在做我想要的,重新加载同一页面而不再提交值。 My use case is an ajax call to the server when session has expired. 我的用例是会话过期时对服务器的ajax调用。 I display an error message saying that the session is lost, then I want the page to reload. 我显示一条错误消息,说会话丢失,然后我想重新加载页面。

简单方法:

history.replaceState(null, document.title, location.href)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM