开发者

C# force page load on browser back click

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 (Forcing page refresh on click of back button)


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.


Another solution is to generate a unique JavaScript variable on the server side (for example, a GUID) and write it to the page through perhaps a registered script. Next, on each page load you will check to see if a cookie exist with that same variable set, if one does, you can be assured that you are viewing a cached page and you should force a reload. Otherwise, store the variable to the same cookie for the next load.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜