Josh, If I used onload="javascript:Scroll();" at the tab and I clicked a control that is set to Auto Postback, the page was reload and Scroll() function was called. The GetCoords() never be called. I added alert in the Scroll() function and it came up blank
every time. If I removed onload="javascript:Scroll();", the GetCoords() function was called every minute. The scrollX and scollY were correct if the control is not set to AutoPostback and returned zeros if the control was set to AutoPostback. The DataGrid
control does not have AutoPostback property. The Sort Expression is set in the Property Builder. It may work differently from the AutoPostback property. Here is my code: <script language="javascript"> function GetCoords() { var scrollX, scrollY; if (document.all)
{ if (!document.documentElement.scrollLeft) scrollX = document.body.scrollLeft; else scrollX = document.documentElement.scrollLeft; if (!document.documentElement.scrollTop) scrollY = document.body.scrollTop; else scrollY = document.documentElement.scrollTop;
} else { scrollX = window.pageXOffset; scrollY = window.pageYOffset; } document.forms[0].scrollLeft.value = scrollX; document.forms[0].scrollTop.value = scrollY; //alert(scrollX); //alert(scrollY); } function Scroll() { var x = document.forms[0].scrollLeft.value;
var y = document.forms[0].scrollTop.value; window.scrollTo(x, y); //alert(x); //alert(y); } window.setInterval('GetCoords()', 1000); </script> <form id="Form1" method="post" runat="server"> <input id="scrollLeft" type="hidden"> <input id="scrollTop" type="hidden">
Thanks, DanYeung
Josh, Hope this time is in better formatting. If I used onload="javascript:Scroll();" to the tab and I clicked a control that is set to Auto Postback, the page was reload and Scroll() function was called. The GetCoords() never be called. I added alert in the
Scroll() function and it came up blank every time. If I removed onload="javascript:Scroll();", the GetCoords() function was called every minute. The scrollX and scollY were correct if the control is not set to AutoPostback and return zeros if the control is
set to AutoPostback. The DataGrid control does not have AutoPostback property. The Sort Expression is set in the Property Builder. It may work differently from the AutoPostback property. Here is my code: <script language="javascript"> function GetCoords()
{ var scrollX, scrollY; if (document.all) { if (!document.documentElement.scrollLeft) scrollX = document.body.scrollLeft; else scrollX = document.documentElement.scrollLeft; if (!document.documentElement.scrollTop) scrollY = document.body.scrollTop; else scrollY
= document.documentElement.scrollTop; } else { scrollX = window.pageXOffset; scrollY = window.pageYOffset; } document.forms[0].scrollLeft.value = scrollX; document.forms[0].scrollTop.value = scrollY; //alert(scrollX); //alert(scrollY); } function Scroll()
{ var x = document.forms[0].scrollLeft.value; var y = document.forms[0].scrollTop.value; window.scrollTo(x, y); alert(x); alert(y); } window.setInterval('GetCoords()', 1000); </script> <form id="Form1" method="post" runat="server"> <input id="scrollLeft" type="hidden">
<input id="scrollTop" type="hidden"> Thanks. DanYeung
OK, I just went through the hassle of testing this with autopostback. It works fine for me. I guess there is only one thing I can suggest you change, in your Scroll() function:
var x = document.getElementById('scrollLeft').value;
var y = document.getElementById('scrollTop').value;
I took care the problem by using anchor. Call the following sub after a control is clicked. Private Sub sGoToAnchor() Dim strAnchorScript As String = "<script language='javascript'>" strAnchorScript += " location.href='#controlid';" strAnchorScript += " </script>"
Page.RegisterStartupScript("sGoToAnchor", strAnchorScript) End Sub DanYeung
Marked as answer by danyeung on Apr 15, 2008 09:22 PM
danyeung
Participant
754 Points
369 Posts
Re: Using javascript to maintain the scroll position.
Mar 20, 2007 04:02 AM|LINK
danyeung
Participant
754 Points
369 Posts
Re: Using javascript to maintain the scroll position.
Mar 20, 2007 04:04 AM|LINK
Sohnee
Contributor
2560 Points
492 Posts
Re: Using javascript to maintain the scroll position.
Mar 20, 2007 09:11 AM|LINK
If you open the component designer generated code and find the Page Load function - you just need to add exactly the same thing, but for pre-render...
I don't have VS 2003 here but it's something like:
this.PreRender = new EventHandler(Page_PreRender);
JoshStodola
Star
13736 Points
3177 Posts
Re: Using javascript to maintain the scroll position.
Mar 20, 2007 01:39 PM|LINK
OK, I just went through the hassle of testing this with autopostback. It works fine for me. I guess there is only one thing I can suggest you change, in your Scroll() function:
var x = document.getElementById('scrollLeft').value; var y = document.getElementById('scrollTop').value;Hope this helps!
JoshStodola
Star
13736 Points
3177 Posts
Re: Using javascript to maintain the scroll position.
Mar 20, 2007 01:40 PM|LINK
Also try changing this in your GetCoords() function:
document.getElementById('scrollLeft').value = scrollX;document.getElementById('scrollTop').value = scrollY
Hope this helps!
danyeung
Participant
754 Points
369 Posts
Re: Using javascript to maintain the scroll position.
Mar 21, 2007 04:47 AM|LINK
danyeung
Participant
754 Points
369 Posts
Re: Using javascript to maintain the scroll position.
Mar 27, 2007 04:16 AM|LINK