“maintainScrollPositionOnPostBack=”true“ ” does not work with google chrome

Pranav Kumar picture Pranav Kumar · Sep 12, 2014 · Viewed 15.8k times · Source
  1. Web.config Level => pages maintainScrollPositionOnPostBack="true" />

  2. Page Level => <%@ Page MaintainScrollPositionOnPostback="true" %>

  3. Code Level => Page.MaintainScrollPositionOnPostBack = true;

  4. Browser Level => browser id="Chrome" parentID="Safari1Plus"> capabilities> capability name="supportsMaintainScrollPositionOnPostback" value="true" /> capabilities> browser>

Any of the 4 ways mentioned above did not work with google chrome. It is working fine with firefox. Kindly provide any solution .

Answer

Darkseal picture Darkseal · Dec 16, 2014

You can add this snippet to your ASP.NET Page/MasterPage (jQuery required):

<asp:HiddenField runat="server" ID="hfPosition" Value="" />
<script type="text/javascript">
    $(function () {
        var f = $("#<%=hfPosition.ClientID%>");
        window.onload = function () {
            var position = parseInt(f.val());
            if (!isNaN(position)) {
                $(window).scrollTop(position);
            }
        };
        window.onscroll = function () {
            var position = $(window).scrollTop();
            f.val(position);
        };
    });
</script>