Reputation: 261
I am attempting to redirect a gridview on selection. However, I am getting stuck on redirection when the page I am trying to redirect to is in a different folder.
The gridview is in a folder named HR. I am trying to redirect this to a file called Staff within a folder called Staff (Staff\Staff). How can I redirect to a different folder?
If e.CommandName = "Select" Then
'Add to session variable; translate the index of clicked to Primary Key
Session.Add("DetailsKey", GridView1.DataKeys(e.CommandArgument).Value.ToString)
Response.Redirect("staff\staff.aspx")
End If
Upvotes: 4
Views: 32301
Reputation: 113352
The main thing is to use /
rather than \
. You aren't redirecting to a folder on the server, but to a path on the website (the fact that this means a folder on your server is just an implementation detail).
You can do all the forms that you can with relative links. Hence "staff/staff.aspx"
goes to the file called staff.aspx in the folder called staff that is in the current folder (assuming your folder-and-file based system). "../staff/staff.aspx"
goes up a folder, then to staff then to staff.aspx. "../../staff/staff.aspx"
goes up two first. "/staff/staff.aspx"
goes to the root of the domain on (http://mysite.com/staff/staff.aspx
, etc).
As well as all of these, "~/staff/staff.aspx"
goes to the root of the application, then to staff within that, then to staff.aspx. This is useful if you work on the site such that this would be in http://localhost/currentProject/staff/staff.aspx
because the project is at http://localhost/currentProject/
but deployed to http://mysite.com/staff/staff.aspx
as the site is at http://mysite.com/
. This way the same code works both ways.
Upvotes: 7
Reputation: 28655
This should do the trick
Response.Redirect("~/staff/staff.aspx");
Upvotes: 3