Click here to Skip to main content
15,877,967 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi i have gridView and records can be long. I have command field to update records. When i click "Edit" the command button makes javascript postback.

Even i set MaintainScrollPositionOnPostback="true", after postback page is not scrolling previous point. What can i do?
Updated 4-Feb-11 4:10am

1 solution

Put the grid inside a panel (rather than scrolling the grid itself) and the following in the head section of the page. This is set for using a MasterPage, but you can remove the "ctl00_MainContentPlaceHolder_" prefix for a regular page.

<script type="text/javascript" language="javascript">
        window.onload = function () {
                var strCook = document.cookie;

                if (strCook.indexOf("!~") != 0) {
                        var intS = strCook.indexOf("!~");
                        var intE = strCook.indexOf("~!");
                        var strPos = strCook.substring(intS + 2, intE);
                        document.getElementById("ctl00_MainContentPlaceHolder_pnlFindings").scrollTop = strPos;

<script type="text/javascript" language="javascript">
        function SetDivPosition() {
                var intY = document.getElementById("ctl00_MainContentPlaceHolder_pnlFindings").scrollTop;
                document.cookie = "yPos=!~" + intY + "~!";

In the Panel, you'll need:

That should do it for you. Works for me, anyway.
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900