How do I scroll to the top of an ASP.NET page after postback?

Posted on 2008-11-04
Last Modified: 2012-05-05
Hi Experts,

I use this on top of my ASP.NET page to maintain the scroll position after postback.

<%@ Page Language="VB" MaintainScrollPositionOnPostback="true" %>

This comes in handy because I have a long form, with Listboxes that do Autopostabacks.  When I click the Submit button though, I want to page to scroll back to the top of the page, because any error messages are displayed on the top of the page.

How can I accomplish this?
Question by:crickpaolo
    LVL 13

    Accepted Solution

    You can either use javascript
    ClientScript.RegisterStartupScript(gettype(),"scroll(0,0)", true);

    or disable MaintainScrollPositionOnPostback during submit click
    Page.MaintainScrollPositionOnPostback = false

    Author Closing Comment

    perfect! thanks!

    Featured Post

    What Security Threats Are You Missing?

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Join & Write a Comment

    This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
    Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
    This video is in connection to the article "The case of a missing mobile phone (". It will help one to understand clearly the steps to track a lost android phone.
    In this sixth video of the Xpdf series, we discuss and demonstrate the PDFtoPNG utility, which converts a multi-page PDF file to separate color, grayscale, or monochrome PNG files, creating one PNG file for each page in the PDF. It does this via a c…

    732 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

    18 Experts available now in Live!

    Get 1:1 Help Now