使用多个 Updatepanels 保持滚动位置 asp.net 局部渲染

Maintain scroll position asp.net partial rendering with multiple Updatepanels

我无法保持具有异步部分呈现的页面的滚动位置。

这是我的 aspx 页面的示例:

<%@ Page Language="C#" MasterPageFile="~/Main.master" AutoEventWireup="true" CodeFile="Page.aspx.cs" Inherits="Page_Page" MaintainScrollPositionOnPostback="true"%>




<asp:Content ID="ContentCo" ContentPlaceHolderID="Cph" runat="Server">



  <asp:UpdatePanel ID="UpdatePanel1" runat="server"  UpdateMode="Conditional" ChildrenAsTriggers="false"> 
            <Triggers>
                <asp:AsyncPostBackTrigger ControlID="Timer1" EventName="Tick"/>
            </Triggers>
            <ContentTemplate> 

            </ContentTemplate>
        </asp:UpdatePanel>
      <asp:Timer ID="Timer1" runat="server" OnTick="Timer1_Tick" Interval="1"></asp:Timer>

        <asp:UpdatePanel ID="UpdatePanel2" runat="server"  UpdateMode="Conditional" ChildrenAsTriggers="false">
            <Triggers>
                <asp:AsyncPostBackTrigger ControlID="Timer2" EventName="Tick"/>
            </Triggers>
            <ContentTemplate>

            </ContentTemplate>
        </asp:UpdatePanel>
     <asp:Timer ID="Timer2" runat="server" OnTick="Timer2_Tick"  Interval="1"></asp:Timer>



   <asp:UpdatePanel ID="UpdatePanel3" runat="server"  UpdateMode="Conditional" ChildrenAsTriggers="false">
            <Triggers>
                <asp:AsyncPostBackTrigger ControlID="Timer3" EventName="Tick"/>
            </Triggers>
            <ContentTemplate>

            </ContentTemplate>
        </asp:UpdatePanel>
    <asp:Timer ID="Timer3" runat="server" OnTick="Timer3_Tick" Interval="1"></asp:Timer>


     <asp:UpdatePanel ID="UpdatePanel4" runat="server"  UpdateMode="Conditional" ChildrenAsTriggers="false">
            <Triggers>
                <asp:AsyncPostBackTrigger ControlID="Timer4" EventName="Tick"/>
            </Triggers>
            <ContentTemplate>

            </ContentTemplate>
        </asp:UpdatePanel>
    <asp:Timer ID="Timer4" runat="server" OnTick="Timer4_Tick" Interval="1"></asp:Timer>



    <asp:UpdatePanel ID="UpdatePanel5" runat="server"  UpdateMode="Conditional" ChildrenAsTriggers="false">
            <Triggers>
                <asp:AsyncPostBackTrigger ControlID="Timer5" EventName="Tick"/>
            </Triggers>
            <ContentTemplate>

            </ContentTemplate>
        </asp:UpdatePanel>
    <asp:Timer ID="Timer5" runat="server" OnTick="Timer5_Tick" Interval="1"></asp:Timer>


     <asp:UpdatePanel ID="UpdatePanel6" runat="server"  UpdateMode="Conditional" ChildrenAsTriggers="false">
            <Triggers>
                <asp:AsyncPostBackTrigger ControlID="Timer6" EventName="Tick"/>
            </Triggers>
            <ContentTemplate>

            </ContentTemplate>
        </asp:UpdatePanel>
    <asp:Timer ID="Timer6" runat="server" OnTick="Timer6_Tick" Interval="1"></asp:Timer>


    </asp:Content>

并且我在 aspx.cs 中为每个 UpdatePanel 添加了所有控件,例如:

var us = LoadControl("~/Controls/Control1.ascx");
 this.Controls.Add(us1);

异步部分呈现有效,但每次呈现控件时,它都会出现在页面顶部, 我该如何解决这个问题?

我想我遇到了同样的问题并通过覆盖 javascript scrollTo 函数解决了。我在页面中插入了以下内容

<script type="text/javascript">
    window.scrollTo = function () { }
</script>