ok, i've amended thwe solution slightly to cope with Micheal's observations
1 : The code for collecting the scroll postions on the initilizeRequest event was fatally flawed due to it not collecting the postions of a DIV where the user had scrolled to the top. This was due to the clause :
myDivs[i].scrollTop > 0
Initially, i had intended to remove this clause so all scroll positions were collected, even when they were at zero. This caused a major problem however. My site, with all it's screen sections, UpdatePanels, Panels etc, my pages ended up having 100+ div controls on the client. Being a cookie n00b, I didn't consider that the cookie collection can only contain 20 values. ASP.NET uses the first one to store the SessionID and the 21st addition was knocking this sessionID out and i was losing Session Data and Login information
as discussed here. So, i made a simple custom control, based on a regular asp:Panel which added the folling onScroll attribute in the OnLoad function thus:
1 protected override void OnLoad(EventArgs e)
2 {
3 //add some javascript to record the scrollTop
4 this.Attributes.Add("onscroll", "document.cookie = this.id + '=' + this.scrollTop;");
5 base.OnLoad(e);
6 }
I was then able to remove the collection function and only have the following JavaScriot on my MasterPage:
<script type="text/JavaScript">
Sys.WebForms.PageRequestManager.getInstance().add_endRequest(SetDivScrollPosition);
function SetDivScrollPosition()
{
var strCook = document.cookie;
if(strCook.length > 0)
{
var cookies = strCook.split(";");
for(var i = 0; i < cookies.length; i++)
{
var mySplit = cookies[i].split("=");
try
{
document.getElementById(mySplit[0].replace(" ", "")).scrollTop = mySplit[1];
}
catch(e)
{
}
}
}
}
</script>
Also, i was unable to supress the visual scrolling. It's only very slight anyway so it wasn't very high on priorities for me
So, it's a little more robust now but is still limited to 19 positions, and that's provided you don't use cookies for anything else!!
Hope this helps somone though
cheers
Tim