monkey_boys monkey_boys - 5 months ago 62
Javascript Question

How to scroll to bottom of page when postback finish in asp.net?

How to scroll to bottom of page when postback finish in asp.net?

I have many details in page when I click "Show Detail" in master detail, this page show many data in my page. So how to to scroll to bottom of page automatically?

Answer

You could register the a javascript to move the scroll to the position of some control that you want, like this:

    protected void Page_Load(object sender, EventArgs e)
    {
        if (IsPostBack)
        {
            RegisterStartupScript("ScrollScript", "document.getElementById('objectId').scrollIntoView(true);");
        }
    }

Changing the objectId in the script for the Id of the object you want to scroll to.

As noted by Guy Starbuk in the comments, RegisterStartupScript is deprecated in .Net 4 and now the recommended way to register a script is:

 ClientScript.RegisterStartupScript(GetType(), "ScrollScript", "document.getElementById('objectId').scrollIntoVie‌​w(true)", true);