In one of the pages of my web applicaiton developed using VS 2005, I have a textbox. When the user enters soem text in the textbox and clicks search button, then I retrieve data pertaining to teh search string and display the same in a datagrid. In teh datagrid, each row represents a report and there is a hyperlink column. Clickign on this column would take the user to another page which displays the complete details of the report. Now I want to provide a back button in the 2nd page(where the complete details of the report are displayed) so that the user can go back to the previous page where he entered the search criteria. I have placed the back button in the second page. In the Click event handler of the back button, when I give a Response.redirect or Server.Transfer, it takes me to the previous page. This is the expected expected behaviour. But I want the page to be the same as it was before leaving it.
For example, If in Page1, I entered the search criteria as msdn and clicked on search, then a datagrid pertainign to this would be dispalyed with say 10 rows. I click ont eh hyperlink in one of the rows ato view the complete details. In Page 2, click Back button. Now I should be redirected to page 1 and the page 1 should contain the search criteria as msdn and the datagrid pertainign to this should also be displayed. How do I achive this?
Try the following code...
use history.go(-2) it take you two pages back.
Hope it helps...
--- Mark as answer if the post meets your requirement!
If page1 is simply displaying search results then you can pass the search term back from page2 using querystring.
1. Page1 passes search term to Page2 ( Response.Redirect("Page2.aspx?searchterm=msdn&otherparameters=xyz") )
2. Page2 stores searchterm in viewstate and displays details
3. Page2 displays aBack button, which on click calls Response.Redirect("Page1.aspx?searchterm=msdn")
4. Page1's page load event checks if a searchterm has been passed, if so then get the results
page1's page load event
if (Request.QueryString["searchterm"] != null)
LoadResults for search term
I had the exact same problem. I placed the following in the Client script. No Server side code was needed:
I tried the same. But history.back() does n't work forme. So I tried adding a link button and set the PostBackUrl property to history.back(-1) and it worked. Why didn't it work for the button control? Any idea?
Use below example
protected void Page_Load(object sender, EventArgs e)
if (Convert.ToString(Session["Action"]) == "search")
txtSearch.Text = Convert.ToString(session["SearchText"]);
//Call the appropriate function for search
//HyperLink OnCommand=" OnCommand_lnkName"
protected void OnCommand_lnkName(object sender, CommandEventArgs e)
session["SearchText"] = txtSearch.Text;
Session["Action"] = "Search";
thanx Bill ....... this is perfect code n it worked for me :) :)