ASP.NET VB.NET Search button on masterpage doesn’t navigate to the correct directory

I have a search input and button in a masterpage that I would like to redirect to the same directory that the user is currently in. If user is in myurl.com/Manage/default.aspx, i would like the redirect to be myurl.com/Manage/search.aspx. If the user is in myurl.com/Field/default.aspx, I would like the redirect to be myurl.com/Field/search.aspx.

I can only get it to redirect to one directory or the other.

I have tried HttpContext.Current.Request.PhysicalApplicationPath, and several other HttpContext ideas that do not work to get the current folder directory a user is in.

Response.Redirect("~/Manage/search.aspx?searchstring=" + qSearch.Text)
or
Response.Redirect("~/Field/search.aspx?searchstring=" + qSearch.Text)

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

I haven’t checked with a master page, but I think it’s easier than it seems. Since you always want the search.aspx page in the current directory, you don’t have to specify the directory.

Response.Redirect("search.aspx?searchstring=" + qSearch.Text)

I think that should always go to the nearest search page.


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x