views:

563

answers:

1

I'd like to know how I can detect that the back button is clicked from the browser.

I have the following situation. On my website I have a search form. When you perform two search actions and then click the back button, the values of my dropdownbox are not stored correctly.

Imagine you search the first time on keywords, after that you search by titles. Now, when you click the back button, you see the results of the keywords, but in the dropdown, titles is still visible. I want keyword to be visible in the dropdown.

In my session I store what the search type is. So that's why I want to know how to force a page_load on the browser back button.

When I disable the cache I get this error message (IE 7) "Webpage has expired"

PS: I've read this thread, but it didn't answer my question (http://stackoverflow.com/questions/818060/forcing-page-refresh-on-click-of-back-button)

+1  A: 

Perhaps you're looking for the wrong solution (an ASP.NET solution rather than a browser solution). I think the controls display that way because the browser is trying to be helpful:

  • You visit search page, select keywords, POST request
  • The page displays keywords results, you select titles and POST request
  • The page displays title results, you click back button
  • The browser either displays the page as it looked when you left, or it re-POSTs your previous request. With the former, you see "titles" in dropdown; with the latter, you see "keywords" in dropsdown.

If this really bothers you, you could just spit out a little JavaScript to change the selected value when the page loads. Of course, if you have auto-postback on change to that value, this could introduce another problem.

expedient
I was thinking of a JavaScript solution, but I can't figure it out. Do you have a suggestion what I could try?
Martijn
by the way I don't have auto-postback on
Martijn
Off the top of my head (with jQuery):$(function() { $("#myControlId").val("Correct Value or Label"); } );
expedient
Thnx but the point is that I don't know the correct (combobox) value when the back button is clicked..
Martijn