473,327 Members | 2,016 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

storing scroll position in hdden field

Hello.

I'm working with ASP.NET serverside and am looking for an easy way to
retain scroll position of the window.

Is there any way that a hidden form field could *always* have the
current document.scrolltop value set to it? Especially right before any
posting to the server is done.

I'm using asp.net datagrid code that does not give me any easy way to
tie javascript functions to controls - otherwise this might be easier.

Basically I guess I need grab to document.scrolltop and send it to the
server (so that I can return it when redering the page onload). But
<body onunload=> does not seem to work with my asp controls.

THANKS IN ADVANCE FOR ANY HELP OR INFORMATION!!!

Jul 23 '05 #1
1 1791
ja***@cyberpine.com wrote:

Hi,
I'm working with ASP.NET serverside and am looking for an easy way to
retain scroll position of the window.

Is there any way that a hidden form field could *always* have the
current document.scrolltop value set to it? Especially right before any
posting to the server is done.


To always have it is different than to have it when the post is done:-)
If you only require it with the posting, then check the following.

---
<style type="text/css">
#foo {
width: 1500px;
height: 1500px;
position:absolute;
padding:50% 0 0 50%;
}
</style>

<div id="foo">
<form action="foo" onsubmit="return primaryHandler(event)">
<input type="text" name="scrollPos">
<input type="submit">
</form>
</div>

<script type="text/javascript">
(function(){

function getCompatModeElement(){
var func;
if(
document.compatMode &&
document.compatMode.indexOf("CSS")!=-1 &&
document.documentElement
){
func=function(){return document.documentElement;}
} else if(document.body) {
func=function(){return document.body;}
} else {
func=function(){return null;}
}
return (getCompatModeElement=func)();
}

function getScrollPos(){
var func;
if(typeof window.pageYOffset=="number") {
func=function(){
return {x:window.pageXOffset, y:window.pageYOffset};
}
} else {
var c=getCompatModeElement();
if(c){
func=function(){
return {x:c.scrollLeft, y:c.scrollTop};
}
} else {
func=function(){
return {x:-1, y:-1};
}
}
}
return (getScrollPos=func)();
}

function saveScrollPos(frm){
var p=getScrollPos();
frm.elements["scrollPos"].value=p.x+","+p.y;
return true;
}

// define the handler
var frm=document.forms[0];
frm.onsubmit=(function(p){
return function(evt){
return saveScrollPos(this) && p ? p(evt) : true;
}
})(frm.onsubmit);
})();

// normal handler
function primaryHandler(evt){return false; /*anything*/}
</script>
---
HTH,
Yep.
Jul 23 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Boniface Frederic | last post by:
Hello, I have frame displaying the last posted messages. I set <meta http-equiv="refresh" content="5"/> to automatically refresh the frame every 5s My problem is; if I scroll the frame to see...
2
by: GrantS | last post by:
I am trying to convert the VB.Net code example povided by http://authors.aspalliance.com/JimRoss/Articles/MaintainScrollPos.aspx into C# (ASP.Net)without success. No errors are thrown in the VB...
4
by: ojorus | last post by:
Hi! I just wonder how I can save a page's scroll position with javascript. (i'm not a javascript developer) I have a PHP-page with two columns; the left contains a lot of thumbnails, and the right...
1
by: JC | last post by:
I'm sure you've all seen the save scroll position from 4 guys from rolla which can be found here > http://aspnet.4guysfromrolla.com/articles/111704-1.aspx BUT try to get that to work AND still be...
4
by: Emmanuel | last post by:
Hi, I have placed a DataList control inside a panel control to obtain a scrollable list using the overflow:auto attribute. The rows in the data list contains and edit LinkButton to enable...
6
by: | last post by:
Hi all, I have a long web form on asp.net 2.0. When I go at the bottom and click on submit, a postback occurs and if there are any validation errors (no client-side checking being done), the...
1
by: Lancelot | last post by:
Hi, I want to keep the scroll position after reload. I tried this: function f_scrollTop() { // returns scroll position } function scrollPosition() {...
7
by: Lit | last post by:
Hi, How can I capture the vertical scroll bar position for a Listbox. I have a Listbox of 100 items + when I click on it I post back remove the item selected. After returning to the client...
12
Frinavale
by: Frinavale | last post by:
I think I'm trying to do something impossible. I have a <div> element with a overflow style set to "scroll". In other words my <div> element allows the user to scroll the content within it. ...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.