SamuraiJack
SamuraiJack

Reputation: 5569

How to redirect to current location using javascript?

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?

Upvotes: 0

Views: 121

Answers (3)

Raghubar
Raghubar

Reputation: 2788

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>");

Upvotes: 0

Ivan Doroshenko
Ivan Doroshenko

Reputation: 942

Just write:

window.location.reload();

Upvotes: 0

Mehran Hatami
Mehran Hatami

Reputation: 12961

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)

Upvotes: 1

Related Questions