我无法维护具有异步部分渲染的页面的滚动位置。
以下是我的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>
我为每个UpdatePanel添加了aspx.cs中的所有控件,如:
var us = LoadControl("~/Controls/Control1.ascx");
this.Controls.Add(us1);
异步部分渲染有效,但每次控件渲染它都会在页面顶部进行, 我该如何解决这个问题?
答案 0 :(得分:0)
我认为我有同样的问题,并通过覆盖javascript scrollTo函数解决。我在页面中插入了以下内容
<script type="text/javascript">
window.scrollTo = function () { }
</script>