Scroll to top when update inside update panel

Posted on 2009-02-09
Last Modified: 2012-05-06
I have a repeater that is placed inside an update panel.
When I click at one of the buttons inside this I want the page to be scrolled to the top.

I have googled a solution: (see code)

The problem with this solution is that it respond to all updates. I want it to execute just when the user clicks a specific button..

somebody knows a easy solution?
<script type="text/javascript" language="javascript">


  function EndRequestHandler(sender, args)





Open in new window

Question by:jimmieandersson
    LVL 15

    Expert Comment

    by:Praveen Venu
    simple.. In the button1_click after all other code execute



    Author Comment

    thanks, I changed your script a little to:

    ScriptManager.RegisterClientScriptBlock(uplShoppingCart, this.GetType(), "scrToTop", "<script>scrollTo(0,0);</script>", false);

    what happens now is that the page first scroll to the top but only stays until the page is fully loaded again (<1 sec). It then goes back to the original scroll position.
    LVL 15

    Expert Comment

    by:Praveen Venu
    check to see if your URL has any #


    System.Web.UI.Page.MaintainScrollPositionOnPostBack = false;
    ScriptManager.RegisterClientScriptBlock(uplShoppingCart, this.GetType(), "scrToTop", "<script>scrollTo(0,0);</script>", false);


    Author Comment

    sorry, no # in URL

    this.Page.MaintainScrollPositionOnPostBack = false;
    gave the same result.

    I also tried setting MaintainScrollPositionOnPostBack  in the aspx @page directive but no difference

    Expert Comment

    I have the same issue.  It's as tho the postback is telling the app to go back to the same position, no matter how I try to override.  I've tried it at the 'onValueChanged' of a hiddenfield.  (The page number) which seems reasonable, but always end up at the same spot.

    Author Comment

    I havn't solved this yet so if you do, please let me know.
    LVL 22

    Accepted Solution

    You are almost there. Here is what you need:
    Change "ctl00_C1_JobsGridView" in the article to your button's generated ID found in page source.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    Suggested Solutions

    Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
    In Part 1 ( we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
    The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
    The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

    729 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    21 Experts available now in Live!

    Get 1:1 Help Now