This problem has answers all over the network, and personally none of them worked, because for me Firefox will try to restore the previous scroll position (wrong), fire the window.scroll event, which will overwrite my hidden field with the wrong position, which is my scrollTo will read. (I have gridviews coming from postbacks, followed by automatic folding of some rows.)
So, here is another solution to this problem - I decided that I only want to restore the scroll position after sending, not updating, so that was enough:
ASPX page:
<form runat="server" onsubmit="$('#hfScroll').val($(window).scrollTop()); return true;"> <input type="hidden" id="hfScroll" value="0" />
JavaScript:
function restoreScroll() { var position = parseInt($('#hfScroll').val()); if (!isNaN(position)) { $(document).scrollTop(position); } }; var prm = Sys.WebForms.PageRequestManager.getInstance(); prm.add_pageLoaded(restoreScroll);
For some reason, in updating the browser, my hidden input is not reset to zero, so sometimes it behaves oddly. I would like to know what to do with it, I think itβs Firefox because it doesnβt happen in IE, but life is too short [he says ... downloaded half the Internet and spent hours on it ..].
Chris source share