8

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!

Mr Lonely
  • 111
  • 2
  • 2
  • 3

9 Answers9

14

Try this:

window.location.href = window.location.href;
karaxuna
  • 26,752
  • 13
  • 82
  • 117
6
location.href = location.href + '?' + Math.random();

This should work.

Jonathan Lidbeck
  • 1,555
  • 1
  • 14
  • 15
Junnan Wang
  • 627
  • 4
  • 12
5

In your code add:

Response.Redirect(Request.RawUrl)
Ryan McDonough
  • 9,732
  • 3
  • 55
  • 76
2

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.

webnoob
  • 15,747
  • 13
  • 83
  • 165
2

Add the following:

Server.Transfer(Request.RawUrl);

George Stocker
  • 57,289
  • 29
  • 176
  • 237
Mamun
  • 21
  • 1
2

The following will solve your problem:

Server.Transfer(Request.RawUrl);
George Stocker
  • 57,289
  • 29
  • 176
  • 237
0

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

Dmitry Pashkevich
  • 13,431
  • 9
  • 55
  • 73
tobspr
  • 8,200
  • 5
  • 33
  • 46
0

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.

Remi Morin
  • 292
  • 2
  • 6
  • 11
0

Simple way:

history.replaceState(null, document.title, location.href)
Israel
  • 1,165
  • 11
  • 11