Link to home
Start Free TrialLog in
Avatar of tejjas_dave
tejjas_dave

asked on

Back button to go back to previous page

I have two pages in my web app. The first page has a grid view of a list of items, beside each row entry, I have a 'View' button. On clicking the 'View' button it navigates to the second page which contains a tabbed view of detailed information/view of the corresponding row entry we clicked on the first page.

Now, what I need is a BACK button on the second webpage which on clicking will take me to the first page. Presently I have a simple back button created in the second web page, but it takes me through each view, whatever I had done in my present page, before it navigates me back to the first page. Im trying to create a back button which will skip any operations or tabbed views i have gone through in the present page (Second page) and will take me to the last instance of the first page.

In the first page I have a gridview that is being populated based on a series of list boxes I also have on the first page itself. On hitting "back" on the second page, I want to go to the last instance/view of the first page, so that way it maintains the state of the listboxes and the gridview. In other words, if i hit back I want the listbox to still have the last item that was selected in it to remain selected and the sorting on the gridview to remain the way it is and so on in the first page.
Any ideas or suggestions?
Avatar of Faizan Sarwar
Faizan Sarwar
Flag of United Kingdom of Great Britain and Northern Ireland image

on view button click
----------------------------------------------------------
Response.Redirect("abc.aspx?BackURL=" + Server.UrlEncode(Request.RawUrl))


//---------------------------------------------------------------------------------
 private void btnBack_Click(object sender, System.EventArgs e) {
        Response.Redirect(GetBackURL(Request.Params("BackURL")));
    }
---------------------------------------------------------------------------------
   public static string GetBackURL(string url) {
        string res = url;
        if ((res.IndexOf("BackURL=") > -1)) {
            string backURL = HttpUtility.UrlDecode(res.Substring((res.IndexOf("BackURL=") + 8)));
            res = res.Replace(("BackURL=" + backURL), ("BackURL=" + HttpUtility.UrlEncode(backURL)));
        }
        return res;
    }

==============================================================
to maintain or pre load values you need to store them in session

hope that helps
Avatar of tejjas_dave
tejjas_dave

ASKER

Hi sm394
Looks like tit should work, Im getting an error saying that System.web.httpRequest.Params cannot be used like a method on the line
Response.Redirect(GetBackURL(Request.Params("BackURL")));

Any suggestions?
yea sorry for syntax mistake
use  instead
Request.Params["BackURL"];
Hi sm394
I tried working with the code that you had mentioned... But it doesn't seem to be taking me back to the last instance of that page. It instead reloads the first page again and when it reloads the first page, it takes the default values as to when it loaded first.
That was a great suggestion though. I was thinking it would work since request.params store all the variables involved... but somehow, it doesent quite work the way i want it. Now, it works similar to just providing a link to the first page. So Im able to go to the page, but just not able to view that last instance that I want to view.
ASKER CERTIFIED SOLUTION
Avatar of Faizan Sarwar
Faizan Sarwar
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial