views:

512

answers:

2

Hi friends,

i need to implement a back button for my asp.net website.I am able to use the javascript method to acheive my requirement.But using this method sometimes I need to click on the back button multiple number times to go back to the previous page.It may be because we are using jquery tabs in our website.To focus on a particular tab,other than the 1st tab on page load I am using Page.ClientScript.RegisterStartupScript(....).So I am unable to take the user back to the previous page with just one click.

I also tried with asp.net-C# methods mentioned in the following link. http://www.dotnetcurry.com/ShowArticle.aspx?ID=89 I am able to go back to the previous page, but its state is being lost.Could someone please help me in acheiveing my requirement?

Details:
I have page1.aspx,page2.aspx(which contains jquery tabs view/edit).

In the page1.aspx there are 2 buttons(View,Edit).If I click on view button it takes me to page2.aspx View tab(1st tab) and if I click on the edit button it has to take me to page2.aspx with Edit tab loaded.both View/Edit tabs contain back button.

Also from the View tab I can navigate to the Edit tab,by clicking on another Edit button present in it.

Thanks.

+1  A: 

The methods you have covered in your question are essentially what is available to you.
You can either
1. Provide a link that uses javascript to make the client go back a page.
2. Provide a link that posts back to the server that redirects you back a page.

I am not sure why the jquery in your webform as described in your question is causing you to click more that once to go back. If you know that it will always take 2 clicks to go back you could try this method:

javascript: window.history.go(-2)

When you are using the postback/redirect method you will always be using a http GET method to retrieve the page you are returning too. If you want to maintain state you will have to do this manually i.e. save the values when leaving the page somewhere, like session or a temporary database, and when returning to the page, during the page load, check to see if the user has these values saved and pre-populate them.

Andy Rose
Hi everyone,Thank you so much for the valuable suggestions.I will try with the options you have all given.Thanks again.
kranthi
A: 

I've done something similar (with automatic redirections though) and I had to keep track of the number of pages to go back in my ViewState (or Session if you're jumping from page to page):

code-behind

public void Page_Load()
{
    Session["pagesToGoBack"] = ((int)Session["pagesToGoBack"])++;
}

mark-up:

<input type="button" value="Back" onclick='javascript:history.go(<%= Session["pagesToGoBack"] %>);' />

Be careful to reset the session variable when needed

Made me feel a bit dirty but it worked :)

Veli