Is there a direct instruction for RESPONSE.REDIRECT to go to previous page?
I have a Web application (Help Desk Ticket System) with an inbox to monitor incoming requests and made some filter buttons that help the user arrange the requests based on requester name, creation date, etc.
Every filter will simply call the same page but will add some code to the query string. Example, if the user presses a button labeled [Sort by Date] here is the code behind for开发者_运维知识库 that button:
Response.Redirect("Inbox.aspx?Filter=DATE")
another button will similarly execute:
Response.Redirect("Inbox.aspx?Filter=NAME")
A GridView will be populated with some rows (Summary of the incoming requests) and ordered by the preference of the user.
Once the user has decided to view the full details any of the incoming requests, a click on any row will lead to
Response.Redirect("Details.aspx?REQ_ID=123")
'where 123 is the request number the user clicked
Then the user is given a chance to update/edit the request using several buttons on the Details.aspx page, but every button will need to return the user to the inbox with the preference of filter that the user had before vising the Details.aspx page.
In other words, I would like to do the following once the user presses a button on the Details.aspx page
Sub btnUpdateRequest() Handles btnUpdateRequest.Click
'My code here for the button action (update/edit/send/cancel)
' once the job is done, return the user to the Inbox.aspx page with the same filter
Response.Redirect("javascript:History.Back()")
End Sub
But I know that Response.Redirect does not accept javascript, and I don't want to split the code between Code Behind file, and ASPX file (adding OnClientClick attribute) because I will need to perform both VB instructions and also redirecting the user.
You could redirect to the referrer URL. You should probably check first to see if it is available.
if (Request.UrlReferrer.AbsoluteUri != null) {
Response.Redirect(Request.UrlReferrer.AbsoluteUri);
}
Below might help you. Place this code inside button click()
Page.RegisterStartupScript("goBack", "<script type=""text/javascript"" language=""javascript"">window.history.go(-1);</script>")
Instead of Page.
you could use ClientScript.
, similar to this:
ClientScript.RegisterStartupScript(
GetType(String),
"goBack",
"<script type=""text/javascript"" language=""javascript"">window.history.go(-2);</script>")
The .go(-2)
in my suggestion is necessary (ReportViewer).
精彩评论