Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Forcing page refresh on click of back button

I've 2 asp.net pages..page A and page B. On clicking a link on page A, user gets redirected to page B.When on page B, if user clicks browser's back button, I need to forcefully invoke page refresh of page A. How do I achieve this functionality? Note:Code needs to be compatible across different browsers...ie IE, firefox, opera, etc

like image 834
Steve Chapman Avatar asked May 03 '09 21:05

Steve Chapman


2 Answers

There is some button property like Autopostback, you can try it and see if ti helps!

like image 107
Blerta Avatar answered Oct 11 '22 01:10

Blerta


I think there is no way for Javascript to tell whether it is the first visit or coming from the back button. So I put the parts of the page that need to be updated in an UpdatePanel, and then do the JavaScript to always refresh these on every page load. Not very elegant but it fixes my problem.

function addLoad(fn) {
    if (window.addEventListener) {
        window.addEventListener("load", fn, false); 
        return true; 
    } else if (window.attachEvent) {
        var r = window.attachEvent("onload", fn); 
        return r;
    } else {
        return false; 
    } 
}
function refreshBack()
{
    __doPostBack("<%= updatePanel1.ClientID %>", "");
    __doPostBack("<%= updatePanel2.ClientID %>", "");
}
addLoad(refreshBack);
like image 42
Francis Huang Avatar answered Oct 11 '22 01:10

Francis Huang