首页 新闻 会员 周边

使用Asp.net Ajax,当Timer刷新时,IE占用内存不断增长问题

0
悬赏园豆:120 [已关闭问题]

我用“Timer”刷新“Label”的内容,通过任务管理器看到IE内存占用不断增长。页面放久了,就内存溢出了。该怎么解决?

写了个简单测试代码:

Default.aspx:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server" />
    <asp:UpdatePanel ID="UpdatePanel1" runat="server" >
        <ContentTemplate>
            <asp:Timer ID="Timer1" runat="server" Interval="100" OnTick="Timer1_Tick" />
            <div>
                <asp:Label ID="Label1" runat="server" Text="你好" />
            </div>
        </ContentTemplate>
    </asp:UpdatePanel>
    </form>
</body>
</html>


Default.aspx.cs:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    { }

    protected void Timer1_Tick(object sender, EventArgs e)
    {
        Label1.Text = "(Ajax.net)现在时间:" + DateTime.Now.ToString();
    }
}

安国候的主页 安国候 | 初学一级 | 园豆:80
提问于:2010-01-26 15:41
< >
分享
其他回答(3)
0

我个人建议你最好不要用那个UpdatePanel,最好手写异步AJAX,
建议用JQUERY,extjs都可以

悟〈--觉 | 园豆:145 (初学一级) | 2010-01-26 15:55
0

这是一段简单的时间显示js,copy一下用就行了:

html:

<div class="clock" id="showClock">这里是时间div</div>

js

Clock();
function Clock()
{
    var time=new Date();
    $('showClock').innerHTML=time.toLocaleTimeString();
    setTimeout('Clock()',1000);
}

function $(id){return document.getElementById(id);}

路过秋天 | 园豆:4787 (老鸟四级) | 2010-01-26 16:06
0

时间这种频繁更新的不建议用timer。楼上说的。用ajax的客户端请求的方法。或者用javascript、jquery结合setTimeou来实现。

邢少 | 园豆:10926 (专家六级) | 2010-01-27 14:02
0

用JQUERY框架setTimeout请求,或者你在头部加上EnableViewState=False;

Wishbay | 园豆:350 (菜鸟二级) | 2010-01-29 10:53
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册