In this article I will explain with an example, how to resolve the MaintainScrollPositionOnPostback not working issue in Firefox and Chrome browsers.
 
 

HTML Markup

The following HTML Markup consists of:
TextBox – For capturing user input.
Button – For submitting text.
This is some text.<br /> This is some text.<br /> This is some text.<br />
This is some text.<br /> This is some text.<br /> This is some text.<br />
This is some text.<br /> This is some text.<br /> This is some text.<br />
This is some text.<br /> This is some text.<br /> This is some text.<br />
This is some text.<br /> This is some text.<br /> This is some text.<br />
This is some text.<br /> This is some text.<br /> This is some text.<br />
This is some text.<br /> This is some text.<br /> This is some text.<br />
This is some text.<br /> This is some text.<br /> This is some text.<br />
This is some text.<br /> This is some text.<br /> This is some text.<br />
This is some text.<br /> This is some text.<br /> This is some text.<br />
This is some text.<br /> This is some text.<br /> This is some text.<br />
This is some text.<br /> This is some text.<br /> This is some text.<br />
This is some text.<br /> This is some text.<br /> This is some text.<br />
This is some text.<br /> This is some text.<br /> This is some text.<br />
This is some text.<br /> This is some text.<br /> This is some text.<br />
This is some text.<br /> This is some text.<br /> This is some text.<br />
<asp:TextBox ID="txtName" runat="server"></asp:TextBox>
<asp:Button ID="btnSubmit" runat="server" Text="Submit" />
 
 

Maintaining scroll position on postback

When the Submit button is clicked, the following event handler is executed.
Inside the window.onload function, a variable is declared by using Request.Form and then a check is performed and window.scrollTo function is set.
Inside the window.onscroll function, a position is set and stored in a variable then, a check is performed if variable is equal to 0.
Then, again checked is performed if it is non-zero value then, it will hold the current vertical scroll position and if not then, it sets the scroll position of this element which is no scrolling has occurred.
Again a check is performed if the scroll position is greater than 0 then, a scroll position is declared and again check is performed if the scroll position is equal to NULL then, the attributes are set using setAttribute function.
Finally, the variable is set to the input value.
<script type="text/javascript">
    window.onload = function () {
        var scrollY = parseInt('<%=Request.Form["scrollY"] %>');
        if (!isNaN(scrollY)) {
            window.scrollTo(0, scrollY);
        }
    };
    window.onscroll = function () {
        var scrollY = document.body.scrollTop;
        if (scrollY == 0) {
            if (window.pageYOffset) {
                scrollY = window.pageYOffset;
            }
            else {
                scrollY = (document.body.parentElement) ? document.body.parentElement.scrollTop : 0;
            }
        }
        if (scrollY > 0) {
            var input = document.getElementById("scrollY");
            if (input == null) {
                input = document.createElement("input");
                input.setAttribute("type", "hidden");
                input.setAttribute("id", "scrollY");
                input.setAttribute("name", "scrollY");
                document.forms[0].appendChild(input);
            }
            input.value = scrollY;
        }
    };
</script>
 
 

Screenshot

ASP.Net MaintainScrollPositionOnPostback not working in Firefox and Chrome
 
 

Browser Compatibility

The above code has been tested in the following browsers.
Microsoft Edge  FireFox  Chrome  Safari  Opera
* All browser logos displayed above are property of their respective owners.
 
 

Demo

 
 

Download