Maintain Scroll Position in Google Chrome after Post Back (WebForms)
Working on some web forms and need to maintain the scroll position in Google Chrome after a postback. Of all the solutions I found this one seems to work best.
http://csharpdotnetfreak.blogspot.com/2012/05/aspnet-maintain-scroll-position-chrome.html
Add a reference to your page:
<script src="../scrollsaver.min.js" type="text/javascript"></script>
In the JS file add the following text:
------------- MINIFIED JS BELOW------------------
// scrollsaver.js // Copyright (C) 2009 M. Mahdi Hasheminezhad (hasheminezhad at gmail dot com) // Maintain scroll position of every element on postbacks and partial updates // This source is licensed under Common Public License Version 1.0 (CPL) // History: // 2009-08-21 First Public Release M. Mahdi Hasheminezhad (http://hasheminezhad.com) (function(){function ls(){var c=document.cookie.split(';');for(var i=0;i<c.length;i++){var p=c[i].split('=');if(p[0]=='scrollPosition'){p=unescape(p[1]).split('/');for(var j=0;j<p.length;j++){var e=p[j].split(',');try{if(e[0]=='window'){window.scrollTo(e[1],e[2]);}else if(e[0]){var o=document.getElementById(e[0]);o.scrollLeft=e[1];o.scrollTop=e[2];}}catch(ex){}}return;}}}function ss(){var s='scrollPosition=';var l,t;if(window.pageXOffset!==undefined){l=window.pageXOffset;t=window.pageYOffset;}else if(document.documentElement&&document.documentElement.scrollLeft!==undefined){l=document.documentElement.scrollLeft;t=document.documentElement.scrollTop;}else{l=document.body.scrollLeft;t=document.body.scrollTop;}if(l||t){s+='window,'+l+','+t+'/';}var es=(document.all)?document.all:document.getElementsByTagName('*');for(var i=0;i<es.length;i++){var e=es[i];if(e.id&&(e.scrollLeft||e.scrollTop)){s+=e.id+','+e.scrollLeft+','+e.scrollTop+'/';}}document.cookie=s+';';}var a,p;if(window.attachEvent){a=window.attachEvent;p='on';}else{a=window.addEventListener;p='';}a(p+'load',function(){ls();if(typeof Sys!='undefined'&&typeof Sys.WebForms!='undefined'){Sys.WebForms.PageRequestManager.getInstance().add_endRequest(ls);Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(ss);}},false);a(p+'unload',ss,false);})();












