0

After researching here:

Maintain Panel Scroll Position On Partial Postback ASP.NET

I have added the ability to maintain scroll position when there is a postback:

    <div id="pagingPanelDiv">
        <asp:ScriptManager ID="ScriptManager1" runat="server" ScriptMode="Release" />
        <script type="text/javascript">
            // It is important to place this JavaScript code after ScriptManager1
            var xPos, yPos;
            var prm = Sys.WebForms.PageRequestManager.getInstance();

            function BeginRequestHandler(sender, args) {
                if ($get('<%=pagingPanel.ClientID%>') != null) {
                // Get X and Y positions of scrollbar before the partial postback
                xPos = $get('<%=pagingPanel.ClientID%>').scrollLeft;
                yPos = $get('<%=pagingPanel.ClientID%>').scrollTop;
            }
        }

        function EndRequestHandler(sender, args) {
            if ($get('<%=pagingPanel.ClientID%>') != null) {
           // Set X and Y positions back to the scrollbar
           // after partial postback
           $get('<%=pagingPanel.ClientID%>').scrollLeft = xPos;
           $get('<%=pagingPanel.ClientID%>').scrollTop = yPos;
       }
   }
   prm.add_beginRequest(BeginRequestHandler);
   prm.add_endRequest(EndRequestHandler);
        </script>
        <asp:UpdatePanel ID="UpdatePanel1" runat="server">
            <ContentTemplate>
                <asp:Panel ID="pagingPanel" runat="server" Height="50px" Width="1175px" ScrollBars="Horizontal" Wrap="false"></asp:Panel>
            </ContentTemplate>
        </asp:UpdatePanel>
    </div>

The issue is that now when a button is pressed no postback occurs and thus the button is not updating the gridview like I want it to. How can I fix this?

Community
  • 1
  • 1
endr3am
  • 21
  • 1
  • 6

2 Answers2

0

Why not just use the built in "MaintainScrollPositionOnPostback" as part of the @Page directive.

If you set that to true it should keep the Scrool Position on Postback.

Hope this helps.

Jeoffrey
  • 1
  • 1
0

Did you check the console debug of the browser?. I used the same solution and when I click in the button located inside the update panel ina gridview row, I see the error below and nothing more happens (it is not doing post back):

POST http://localhost:37158/Issues/ScheduledNotes.aspx 500 (Internal Server Error) ScriptResource.axd?d=Xrr7TH9urSaaTnw8W2o5y8u0hPDzkm3GN-PAUDkj7QXbj4srXDMFfsYEcxq9JlkF8RMkpxmbT6sI3n…:6066
Uncaught Sys.WebForms.PageRequestManagerServerErrorException: Sys.WebForms.PageRequestManagerServerErrorException: An unknown error occurred while processing the request on the server. The status code returned from the server was: 500 ScriptResource.axd?d=Xrr7TH9urSaaTnw8W2o5y8u0hPDzkm3GN-PAUDkj7QXbj4srXDMFfsYEcxq9JlkF8RMkpxmbT6sI3n…:237

The error is related only with the update panel and no the whole solution, because I tried to add only the update panel and the same error appears.

Liz Barraza
  • 133
  • 1
  • 7