What is the equivalent code of Response.Redirect(~/Account/Login.aspx");
in javascript?
I tried : window.location="~/Account/Login.aspx"
but the ~
is not accepted in javascript. so, what is the alternative code?
Note: the javascript script is made in the server side in the Page_Load
method by using ClientScript.RegisterClientScriptBlock
.
What is the equivalent code of Response.Redirect(~/Account/Login.aspx");
in javascript?
I tried : window.location="~/Account/Login.aspx"
but the ~
is not accepted in javascript. so, what is the alternative code?
Note: the javascript script is made in the server side in the Page_Load
method by using ClientScript.RegisterClientScriptBlock
.
3 Answers
Reset to default 13use
window.location='<%= ResolveUrl("~/Account/Login.aspx") %>'
EDIT: if it is created in codebehind, then use
string.Format("window.location='{0}';", ResolveUrl("~/Account/Login.aspx"))
Try this:
window.location='<%= ResolveUrl("~/Account/Login.aspx") %>';
The ~ is replaced by the application URL in .NET, but this is not done in Javascript.
Try:
Page.RegisterClientScriptBlock(typeof(_Default), "Redirect", "document.location.href = '" + ResolveUrl("~/Account/Login.aspx") + "';", true);
I would ask as to why you are doing a client-side redirect from the server-side though? Would it not be more appropriate to do a Response.Redirect
instead?