Reset scroll position after Async postback - ASP.NET

前端 未结 8 1414
花落未央
花落未央 2020-11-30 06:08

What is the best way to reset the scroll position to the top of page after the an asynchronous postback?

The asynchronous postback is initiated from a ASP.NET Grid

8条回答
  •  无人及你
    2020-11-30 06:38

    Here is the perfect solution to reset scroll bar position to TOP in AJAX

    Client Side Code

    function ResetScrollPosition()
    {
        setTimeout("window.scrollTo(0,0)", 0);
    }
    

    Server Side Code

    ScriptManager.RegisterStartupScript(Page, this.GetType(), "ScrollPage", "ResetScrollPosition();", true);
    

    Only,window.scrollTo(0,0) will not work. Ajax will take precedence in this case so you have to use setTimeout function with that.

提交回复
热议问题