473,326 Members | 2,023 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,326 software developers and data experts.

Reset scroll position

I hope someone has an answer: MaintainScrollPositionOnPostback works great.
But, the problem is that sometimes we need to manually reset the scroll
position back to the top (such as when hiding a panel and displaying
different panel).

1) Temporarily setting MaintainScrollPositionOnPostbox=False in the postback
event *seems* to work... but it's not the right answer as it messes up any
subsequent event postbacks.
2) Registering a startup script (window.scrollTo(0,0);) doesn't work because
ASP.NET puts its own scroll logic after it.

Basically we need a way to do something like Page.SetScroll(0,0) to manually
override the values saved by the MaintainScrollPositionOnPostback feature.
Any ideas?

--
-C. Moya
www.cmoya.com
Feb 13 '07 #1
6 24900
Wow. No takers? I didn't think there would be here. But, this is a pretty
common scenerio. No one is designing pages that actually have enough content
to scroll?

Anyway, I've just resorted to manually turning off
MaintainScrollPositionOnPostback in the event when I need the page to scroll
to the top (ASP.NET automatically turns it on in the next postbox). This
achieves the effect of scrolling to the top at the expense of the very next
postback doing the same (which is not ideal).

--
-C. Moya
www.cmoya.com
"C. Moya" <cm*@nospam.comwrote in message
news:uB**************@TK2MSFTNGP03.phx.gbl...
>I hope someone has an answer: MaintainScrollPositionOnPostback works great.
But, the problem is that sometimes we need to manually reset the scroll
position back to the top (such as when hiding a panel and displaying
different panel).

1) Temporarily setting MaintainScrollPositionOnPostbox=False in the
postback event *seems* to work... but it's not the right answer as it
messes up any subsequent event postbacks.
2) Registering a startup script (window.scrollTo(0,0);) doesn't work
because ASP.NET puts its own scroll logic after it.

Basically we need a way to do something like Page.SetScroll(0,0) to
manually override the values saved by the MaintainScrollPositionOnPostback
feature. Any ideas?

--
-C. Moya
www.cmoya.com

Feb 14 '07 #2
Hi,

C. Moya wrote:
I hope someone has an answer: MaintainScrollPositionOnPostback works great.
But, the problem is that sometimes we need to manually reset the scroll
position back to the top (such as when hiding a panel and displaying
different panel).

1) Temporarily setting MaintainScrollPositionOnPostbox=False in the postback
event *seems* to work... but it's not the right answer as it messes up any
subsequent event postbacks.
2) Registering a startup script (window.scrollTo(0,0);) doesn't work because
ASP.NET puts its own scroll logic after it.
Startup scripts are added to the bottom of the page. The body.onload
event (JavaScript) will occur even after that. So I think that you
should try and add the "window.scrollTo" code in the body onload event.

To do this, you can add runat="server" to the body tag, give it an ID,
and then in the code behind use the "Attributes" collection. I didn't
test but I think it should work.
Basically we need a way to do something like Page.SetScroll(0,0) to manually
override the values saved by the MaintainScrollPositionOnPostback feature.
Any ideas?
HTH,
Laurent
--
Laurent Bugnion [MVP ASP.NET]
Software engineering, Blog: http://www.galasoft-LB.ch
PhotoAlbum: http://www.galasoft-LB.ch/pictures
Support children in Calcutta: http://www.calcutta-espoir.ch
Feb 17 '07 #3
"Laurent Bugnion [MVP]" <ga*********@bluewin.chwrote in message
news:OD**************@TK2MSFTNGP04.phx.gbl...
Startup scripts are added to the bottom of the page. The body.onload event
(JavaScript) will occur even after that. So I think that you should try
and add the "window.scrollTo" code in the body onload event.

To do this, you can add runat="server" to the body tag, give it an ID, and
then in the code behind use the "Attributes" collection. I didn't test but
I think it should work.
Yeah, I considered that... but then I saw that the
MaintainScrollBackPosition uses it too. I haven't tried experimenting yet.

--
-C. Moya
www.cmoya.com
Feb 18 '07 #4
hey, I'm suffering from exactly the same problem. I haven't got a proper solution yet, but I think I'm on the right track. It depends how your pages are constructed, but I have multiple user controls on a single page, each of which are made visible in turn, through a 4-step process.

In the PreRender event of each control, you can read this.Request["__EVENTTARGET"], cast it to type WebControl, and use FindControl() to determine whether it is a child of the current UserControl.

In my implementation, I can safely assume that if the event was raised from a different control, I want to reset the scroll position to 0,0 (moving between steps).

Conversely, if the event was raised from inside the same control, it's probably just a validation failure etc, for which I want to maintain the scroll position.

I dont think this can easily be integrated with MaintainScrollPositionOnPostback, so I've still got to write the JS to control the scrolling myself and include it dynamically, based on the logic above.

Just thought the concept might help you a little!?

EggHeadCafe.com - .NET Developer Portal of Choice
http://www.eggheadcafe.com
Apr 2 '07 #5
No, scratch that - I've found a better way! :)

Include this JS function in your page:

function resetDotNetScrollPosition()
{
var scrollX = document.getElementById('__SCROLLPOSITIONX');
var scrollY = document.getElementById('__SCROLLPOSITIONY');

if(scrollX != null && scrollY != null)
{
scrollX.value = 0;
scrollY.value = 0;
}
}

then in whichever server event you need to reset the scroll position, register it as a startup script:

Page.ClientScript.RegisterStartupScript(Page.Clien tScript.GetType(), Page.ClientID, "resetDotNetScrollPosition();", true);

...it works because this startup script gets inserted *before* ASP.NET's calls to restore the scroll position, so it ends up restoring the scroll position to 0,0. Here is the generated HTML from the end of my page:
------------------------------------------------

resetDotNetScrollPosition(); << LOOK!

theForm.oldSubmit = theForm.submit;
theForm.submit = WebForm_SaveScrollPositionSubmit;

theForm.oldOnSubmit = theForm.onsubmit;
theForm.onsubmit = WebForm_SaveScrollPositionOnSubmit;

theForm.oldOnLoad = window.onload;
window.onload = WebForm_RestoreScrollPosition;

EggHeadCafe.com - .NET Developer Portal of Choice
http://www.eggheadcafe.com
Apr 2 '07 #6
Nice!

--
-C. Moya
www.cmoya.com
<guinnesswrote in message news:20***************@tiscali.co.uk...
No, scratch that - I've found a better way! :)

Include this JS function in your page:

function resetDotNetScrollPosition()
{
var scrollX = document.getElementById('__SCROLLPOSITIONX');
var scrollY = document.getElementById('__SCROLLPOSITIONY');

if(scrollX != null && scrollY != null)
{
scrollX.value = 0;
scrollY.value = 0;
}
}

then in whichever server event you need to reset the scroll position,
register it as a startup script:

Page.ClientScript.RegisterStartupScript(Page.Clien tScript.GetType(),
Page.ClientID, "resetDotNetScrollPosition();", true);

..it works because this startup script gets inserted *before* ASP.NET's
calls to restore the scroll position, so it ends up restoring the scroll
position to 0,0. Here is the generated HTML from the end of my page:
------------------------------------------------

resetDotNetScrollPosition(); << LOOK!

theForm.oldSubmit = theForm.submit;
theForm.submit = WebForm_SaveScrollPositionSubmit;

theForm.oldOnSubmit = theForm.onsubmit;
theForm.onsubmit = WebForm_SaveScrollPositionOnSubmit;

theForm.oldOnLoad = window.onload;
window.onload = WebForm_RestoreScrollPosition;

EggHeadCafe.com - .NET Developer Portal of Choice
http://www.eggheadcafe.com

Apr 8 '07 #7

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

Similar topics

1
by: Scott M | last post by:
Hi, I am writing a small game that is using a form 800 * 600. The form can be scrolled vertically up to a height of 1200 (basically the form can be scrolled down one screen vertically). The...
4
by: Joe | last post by:
I have a very simple need - I need javascript code to reset a DIV that the user may have scrolled down. It doesn't need to smoothly scroll or anything - just jump right to the top. All help...
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...
3
by: rmunson8 | last post by:
I have added Panel control to a web page which contains a GridView. The Panel's ScrollBars property is set to auto. When I select the Select CommanField button for a row (which obviously causes a...
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...
8
praclarush
by: praclarush | last post by:
Ok, I'm new to JavaScript and I'm taking a class for it the assignment in it I'm supposed to create edit a pre-made page to display a marquee that automatically scrolls for the user, as well as give...
1
by: Mark | last post by:
Hi. I have a page which has an update panel covering all of it. When I do a server postback via the update panel, the screen remains in the same scroll position - which is ok most of the time....
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: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
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: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
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...

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.