3

Got a timer inside an updatepanel. It constantly refreshes (about every 2.5 seconds). If it refreshed while scrolling it sets the scroll position back to what it was berfore the partial update :(

I'm using ASP.NET 3.5 and MaintainScrollPositionOnPostback is set to false (even if set to true behaviour doesn't change).

No clue why this happens, but usability is annoying...

Kind regards, Sascha

Sascha
  • 10,231
  • 4
  • 41
  • 65

1 Answers1

7

We had a similar problem where an asynchronous postback would reset the user to the top of a very long page. We resolved it after finding the following code at: http://forums.asp.net/t/1047815.aspx

We inserted the following javascript on our page after the ScriptManager on the page.

<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>

<script type="text/javascript">
    var prm = Sys.WebForms.PageRequestManager.getInstance();
    prm.add_beginRequest(beginRequest);

    function beginRequest() {
        prm._scrollPosition = null;
    }
</script>

This made it so the postback did not reset the users scroll position when the postback returned.

I'm not sure if this is exactly the problem that you are experiencing. You could also take a look at this post: Reset scroll position after Async postback - ASP.NET which discusses a more robust method of setting the scroll position after a postback occurs.

Community
  • 1
  • 1
sgriffinusa
  • 4,203
  • 1
  • 25
  • 26
  • Got an error Sys.Webforms undefined. But on the link you posted, there's another snippet, (write your own empty scrollTo function). That did the trick. Must investigate why I get an error with your example ... – Sascha Mar 11 '09 at 07:22
  • May be one of the following: 1. Javascript appears before the ScriptManager http://bit.ly/8askn 2. Web.Config not setup for AJAX. http://bit.ly/ktZK2 3. EnablePartialRendering needs to be set to true on your ScriptManager. http://bit.ly/14Gsj Most likely culprit is #3. – sgriffinusa Mar 11 '09 at 14:06
  • Culprit was (1). Tried and after that read your post. Thanks. – Sascha Mar 11 '09 at 15:33
  • @sgriffinusa, Thanks a lot to save my day. – Kailash Bhakuni Jul 29 '18 at 06:35