Can I redirect the Admin->abc.aspx to rootfolder->index.aspx using javascript?
Ju开发者_如何学JAVAst explaining my question in short.
I have asp.net website with root structure as following
root Directory->
Admin
abc.aspx
xyz.aspx
index.aspx
Now I want to redirect from abc.aspx
to index.aspx
.
I'm using JavaScript as
window.location = "../index.aspx";
but found no any luck.
This is a very odd trick. But it works.
Have a hidden field in the page. This needn't be a server control. (Or if you want, you can even do without one.). For brevity sake I am assuming you've used a server HiddenField control, called hfNavUrl
. Do something like this.
hfNavUrl.Value = Me.ResolveUrl("~/index.aspx")
Once this renders you get the full url. Find the hidden field value in javascript and work your javascript code:
window.location.href = document.getElementByValue('hfNavUrl').value;
Update: Doing it w/o using controls
There are two ways about this. However, you'd have to embed the code in your page markup file (i.e. the *.aspx file). The javascript way is something like holding the url into a variable.
var url = '<%= Me.ResolveUrl("~/index.aspx") %>';
You can now make use of the value inside of this variable at a later point of time.
Alternatively, you can simply have a <a>
element with its href
set directly:
<a href="<%= Me.ResolveUrl("~/Index.aspx") %>">Home</a>
Ps: Me.
whatever is the vb.net way of doing things. Replace it with this
if you are working with c#
Try using "window.location.replace('/index.aspx')"
You issue will be resolved by one of the below solutions from java script by providing the type of application.
If Application created as Website
windows.location='/index.aspx';
and
If Application created as Virtual directory
windows.location='/[Virtual Directory Name of Root Folder]/index.aspx';
精彩评论