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 Chriss 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
Here is my situation; hopefully someone can help me out (I am using .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>
 
You will be better off asking in the javascript forum for any client-side questions.

However, you could also look into the Page.MaintainScrollPositionOnPostBack property to see if that helps.


-------------------------------------------------------

Mark,
[URL unfurl="true"]http://aspnetlibrary.com[/url]
[URL unfurl="true"]http://mdssolutions.co.uk[/url] - Delivering professional ASP.NET solutions
[URL unfurl="true"]http://weblogs.asp.net/marksmith[/url]
 
You think? I thought this thread would be more appropriate since the problem is not in the java script. I’ll give it a try though.

Yes I tried the Page.MaintainScrollPositionOnPostBack property, but that only works at the page level. Since this is a scroll within a DIV it does not work.
 
You think? I thought this thread would be more appropriate since the problem is not in the java script.
The problem is in javascript though. You want to scroll to a certain position of a client element on the client's browser. The server has absolutely no concept of browser position and you would face the same problem whether you used ASP.NET, ASP, PHP, ColdFusion etc. Therefore, it is a client-side problem.


-------------------------------------------------------

Mark,
[URL unfurl="true"]http://aspnetlibrary.com[/url]
[URL unfurl="true"]http://mdssolutions.co.uk[/url] - Delivering professional ASP.NET solutions
[URL unfurl="true"]http://weblogs.asp.net/marksmith[/url]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top