Mr Lonely
Mr Lonely

Reputation: 111

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

How to refresh and reload the page without resending the POST data?

I have tried location.reload() which works absolutely fine on Chrome(which was the testing environment while development). But IE and Firefox went into an Infinite Loop in JS - reposting a lot of junk/duplicate data.

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!

Upvotes: 8

Views: 25970

Answers (9)

Israel
Israel

Reputation: 1464

Simple way:

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

Upvotes: 0

Remi Morin
Remi Morin

Reputation: 292

I've try reload too, and reload(true) both not exactly doing what I wanted.

I've seen that Location Object have other method (than reload) since I wanted to request the page in "get" I just did:

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. I display an error message saying that the session is lost, then I want the page to reload.

Upvotes: 0

Junnan Wang
Junnan Wang

Reputation: 657

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

This should work.

Upvotes: 6

tobspr
tobspr

Reputation: 8386

use location.reload(true). This "hard" reloads the page ..

Upvotes: 0

The following will solve your problem:

Server.Transfer(Request.RawUrl);

Upvotes: 2

Mamun
Mamun

Reputation: 21

Add the following:

Server.Transfer(Request.RawUrl);

Upvotes: 2

webnoob
webnoob

Reputation: 15934

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.

Upvotes: 2

Ryan McDonough
Ryan McDonough

Reputation: 10012

In your code add:

Response.Redirect(Request.RawUrl)

Upvotes: 5

karaxuna
karaxuna

Reputation: 26940

Try this:

window.location.href = window.location.href;

Upvotes: 14

Related Questions