0

在这里研究后:

在部分回发 ASP.NET 上保持面板滚动位置

我添加了在回发时保持滚动位置的功能:

    <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>

问题是现在按下按钮时不会发生回发,因此按钮不会像我想要的那样更新gridview。我怎样才能解决这个问题?

4

2 回答 2

0

为什么不直接使用内置的“MaintainScrollPositionOnPostback”作为@Page 指令的一部分。

如果将其设置为 true,则应在回发时保留 Scrool 位置。

希望这可以帮助。

于 2013-09-19T19:40:13.330 回答
0

您是否检查了浏览器的控制台调试?我使用了相同的解决方案,当我单击位于 gridview 行中更新面板内的按钮时,我看到下面的错误并且没有任何事情发生(它没有回发):

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

该错误仅与更新面板有关,与整个解决方案无关,因为我尝试仅添加更新面板并出现相同的错误。

于 2013-11-04T07:08:11.477 回答