ASP页面滚动到顶部的UpdatePanel上更新 [英] ASP page scrolls to top on UpdatePanel update
问题描述
我有一个问题,我有一个使用一个计时器来触发更新与新百分点ASP图(在本质上的 http://www.4guysfromrolla.com/articles/121609-1.aspx 下的创建实时图表)。我在哪里,只要计时器滴答声,整个页面滚动到顶部的问题。我怎样才能保持当计时器滴答的页面滚动位置?我试着在 http://www.4guysfromrolla.com/articles/111704-的说明1.aspx 和其他一些类似的JavaScript的解决方案,但在x和y的变量越来越消灭每当计时器刻度。
I am having a problem where I have an UpdatePanel that uses a timer to trigger to update an ASP graph with new points (essentially the guide at http://www.4guysfromrolla.com/articles/121609-1.aspx under "Creating Real Time Charts"). I'm having a problem where whenever the timer ticks, the entire page scrolls to the top. How can I maintain the scroll position in the page when the timer ticks? I've tried the instructions at http://www.4guysfromrolla.com/articles/111704-1.aspx and several other similar JavaScript solutions, but the x and y variables are getting wiped out whenever the timer ticks.
code:
<%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="WebApplication4._Default" %>
<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent"></asp:Content>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
<asp:ScriptManager ID="scmManager" runat="server"></asp:ScriptManager>
<asp:UpdatePanel ID="updRealtimeChart" UpdateMode="Conditional" runat="server">
<ContentTemplate>
<asp:Chart ID="chtRandomData" ...></asp:Chart><br />
<asp:Repeater ID="valueRepeater"...></asp:Repeater>
<asp:Label ID="errorLabel" Font-Bold="true" Font-Size="Larger" ForeColor="Firebrick" BackColor="Khaki" runat="server"></asp:Label>
<asp:Timer ID="tmrRefreshChart" runat="server" Interval="300"></asp:Timer>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="periodUpdate" />
</Triggers>
</asp:UpdatePanel>
...etc rest of the page...
编辑:在code后面,我已经试过这种检查是怎么回事:
In the code behind, I've tried this to check what is going on:
public partial class _Default : System.Web.UI.Page
{
public int count = 0;
protected void Page_Init(object sender, EventArgs e)
{
Page.MaintainScrollPositionOnPostBack = true;
count++;
}
protected void Page_Load(object sender, EventArgs e)
{
errorLabel.Text += count;
... }
当运行此,在UpdatePanel连续增加了一个1到errorLabel,表明在Page_Load和Page_Init功能仅发生一次,但更新面板仍移位滚动位置。
When I run this, the UpdatePanel continuously adds a "1" to the errorLabel, indicating that the Page_Load and Page_Init functions are only occurring once, but the update panel is still shifting the scroll position.
推荐答案
这看起来像一个熟悉的.NET的Bug。在Timer控件设置的ClientIDMode =自动应该修复它。
This looks like a familiar .NET Bug. Setting ClientIDMode=Auto on the Timer control should fix it
这篇关于ASP页面滚动到顶部的UpdatePanel上更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!