473,666 Members | 2,368 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Reset scroll position

I hope someone has an answer: MaintainScrollP ositionOnPostba ck 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 MaintainScrollP ositionOnPostbo x=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.scrollT o(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 MaintainScrollP ositionOnPostba ck feature.
Any ideas?

--
-C. Moya
www.cmoya.com
Feb 13 '07 #1
6 24949
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
MaintainScrollP ositionOnPostba ck 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.com wrote in message
news:uB******** ******@TK2MSFTN GP03.phx.gbl...
>I hope someone has an answer: MaintainScrollP ositionOnPostba ck 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 MaintainScrollP ositionOnPostbo x=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.scrollT o(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 MaintainScrollP ositionOnPostba ck
feature. Any ideas?

--
-C. Moya
www.cmoya.com

Feb 14 '07 #2
Hi,

C. Moya wrote:
I hope someone has an answer: MaintainScrollP ositionOnPostba ck 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 MaintainScrollP ositionOnPostbo x=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.scrollT o(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.scrollT o" 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 MaintainScrollP ositionOnPostba ck 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*********@bl uewin.chwrote in message
news:OD******** ******@TK2MSFTN GP04.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.scrollT o" 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
MaintainScrollB ackPosition 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["__EVENTTAR GET"], 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 MaintainScrollP ositionOnPostba ck, 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 resetDotNetScro llPosition()
{
var scrollX = document.getEle mentById('__SCR OLLPOSITIONX');
var scrollY = document.getEle mentById('__SCR OLLPOSITIONY');

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.ClientScri pt.RegisterStar tupScript(Page. ClientScript.Ge tType(), Page.ClientID, "resetDotNetScr ollPosition();" , 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:
------------------------------------------------

resetDotNetScro llPosition(); << LOOK!

theForm.oldSubm it = theForm.submit;
theForm.submit = WebForm_SaveScr ollPositionSubm it;

theForm.oldOnSu bmit = theForm.onsubmi t;
theForm.onsubmi t = WebForm_SaveScr ollPositionOnSu bmit;

theForm.oldOnLo ad = window.onload;
window.onload = WebForm_Restore ScrollPosition;

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

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

Include this JS function in your page:

function resetDotNetScro llPosition()
{
var scrollX = document.getEle mentById('__SCR OLLPOSITIONX');
var scrollY = document.getEle mentById('__SCR OLLPOSITIONY');

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.ClientScri pt.RegisterStar tupScript(Page. ClientScript.Ge tType(),
Page.ClientID, "resetDotNetScr ollPosition();" , 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:
------------------------------------------------

resetDotNetScro llPosition(); << LOOK!

theForm.oldSubm it = theForm.submit;
theForm.submit = WebForm_SaveScr ollPositionSubm it;

theForm.oldOnSu bmit = theForm.onsubmi t;
theForm.onsubmi t = WebForm_SaveScr ollPositionOnSu bmit;

theForm.oldOnLo ad = window.onload;
window.onload = WebForm_Restore ScrollPosition;

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
2455
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 user controls a picturebox (my sprite) with the cursor keys When the sprite hits the y value of 600 the screen scrolls down to display the bottom part of the screen (by focusing on a hidden
4
41064
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 gratefully received. Joe
4
3646
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 contain a bigger picture of the thumbnailed selected. The problem is that all these thumbnails (and the big picture) are placed quite far down in the document. (a lot of text is at the top.) What I want is that when a thumbnail is clicked, the...
1
8677
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 able to set the focus to a control. Here's the problem, when you set the focus by using the registerstartupscript method the control gets the focus after the scroll position has been set. When this happens the scroll position
3
6073
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 postback), the scroll position resets to the top. I was unable to figure out how to not force a postback or how to reset the scroll position of the GridView. What are my options here?
7
5590
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 browser the list box scroll position is at the top.
8
12594
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 an option to start, stop and reset the marquee. Now I have most of this done already, what I'm having problems with is that when i start the marquee it moves to the right, but i need to have it move from the bottom, upwards. heres my code (I'm not...
1
2273
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. BUT - if on one of these postbacks within the update panel, I need to reset the scroll position of the screen to the top - how can I do that? I've tried .focus() on a control at the top of the page, but this
12
7844
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. There are a number of elements within this <div> that cause the <div> to participate in an Ajax call to the server. In order to maintain the scroll position of the <div> during the Ajax request I store the scroll value in a hidden field so that when...
0
8440
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8866
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8781
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8638
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7381
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4193
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4365
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2006
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1769
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.