0

I am trying to redirect to current page using javascript from server side using this code ..

  ScriptManager.RegisterStartupScript(this, this.GetType(), "pop", "<script>alert('Record saved with claim number " + lastid + ".');var currentPageUrl =document.location.toString().toLowerCase();window.location.assign('currentPageUrl')</script>", false);

But it does not work. How can I make it work?

SamuraiJack
  • 5,131
  • 15
  • 89
  • 195
  • @NK No its not a duplicate of that question because I was NOT looking for a way to RELOAD my page with javascript. I wanted to REDIRECT to the current URL using javascript. I made it clear in my comment on Ivan Doroshenko's answer. – SamuraiJack Apr 02 '14 at 09:29
  • http://stackoverflow.com/questions/503093/how-can-i-make-a-redirect-page-in-jquery-javascript – N K Apr 02 '14 at 09:48
  • still, i wanted to redirect to current page. ;) – SamuraiJack Apr 02 '14 at 09:57

3 Answers3

1

you should just remove the quotes, because currentPageUrl is a JavaScript variable, but you pass it just as a string. change:

window.location.assign('currentPageUrl')

to

window.location.assign(currentPageUrl)
Mehran Hatami
  • 12,723
  • 6
  • 28
  • 35
0

Just write:

window.location.reload();
Ivan Doroshenko
  • 944
  • 7
  • 13
  • 1
    Reload is not what was looking for.. the reason is that reload resubmit the form. So if I save some data on button click and then use reload then the button click even will get fired all over again. – SamuraiJack Apr 02 '14 at 07:42
0

Try This.

Page.ClientScript.RegisterStartupScript(this.GetType(), "success_msg_1", "<script language='javascript' type='text/javascript'>alert('Record saved with claim number " + lastid + ".');location.replace('pageurl');</script>");
Raghubar
  • 2,768
  • 1
  • 21
  • 31