Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Maintaining the scroll position of a Panel

Status
Not open for further replies.

ClevelandSteve

Programmer
Apr 22, 2004
22
US
I posted this in the ASP.Net forum but it was suggested I post the question here, so here goes. In ASP.Net 2.0 I have a gridview inside of a panel control. The panel has ScrollBars="Auto" so when the height of the gridview exceeds the height of the screen it becomes scrollable. The problem I ran into is when a user scrolls the panel and evokes a row editing event in the gridview, after the postback occurs the panel’s scroll position returns to the top. After searching the internet the favored solution is to use the java script code below and link it to the onscroll event of the panel. But there doesn’t seem to be an onscroll event in a panel or DIV. What am I missing here?

<script type="text/javascript">
window.onload = function(){
var strCook = document.cookie;
if(strCook.indexOf("!~")!=0){
var intS = strCook.indexOf("!~");
var intE = strCook.indexOf("~!");
var strPos = strCook.substring(intS+2,intE);
document.getElementById("grdWithScroll").scrollTop =strPos;
}
}
function SetDivPosition(){
var intY = document.getElementById("grdWithScroll").scrollTop;
document.title = intY;
document.cookie = "yPos=!~" + intY + "~!";
}
</script>
 
Huh, visual studio will raise an “‘onsroll’ is not a valid attribute” warning but if I just ignore it and run the page anyway everything works fine. Odd.

I do like your idea better of calling the javascript on the click event. It keeps the scroll from lagging. Thanks for the idea.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top