使用带有JavaScript调用的UpdatePanel时可能存在的内存链接

使用带有JavaScript调用的UpdatePanel时可能存在的内存链接,javascript,asp.net,memory-leaks,updatepanel,Javascript,Asp.net,Memory Leaks,Updatepanel,在ASPX中: <%@ Page Language="C#" AutoEventWireup="true" CodeFile="TimerUpdate3.aspx.cs" Inherits="TimerUpdate3" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> <html xmlns="http://

在ASPX中:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="TimerUpdate3.aspx.cs" Inherits="TimerUpdate3" %>  
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">  
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>Untitled Page</title>
    <script type="javascript">
        showMessage(msg) { alert(msg); }
    </script>
</head>
<body>
<form id="form1" runat="server">
  <asp:ScriptManager ID="ScriptManager1" runat="server" />
  <asp:Timer ID="Timer1" OnTick="Timer1_Tick" runat="server" Interval="1000" />
  <asp:UpdatePanel ID="UpdatePanel1" UpdateMode="Conditional" runat="server">
    <Triggers>
        <asp:AsyncPostBackTrigger ControlID="Timer1" EventName="Tick" />
    </Triggers>
    <ContentTemplate>
        <asp:Label ID="Label1" runat="server" Text="Not refreshed yet..."></asp:Label>
        <table id="Incidents" runat="server" cellspacing="0" cellpadding="5" style="padding:0; width:400px;"></table>
    </ContentTemplate>
  </asp:UpdatePanel>
</form>
</body>
</html>

无标题页
showMessage(msg){alert(msg);}
在C#中:

使用系统;
使用System.Web.UI;
使用System.Web.UI.HTMLControl;
公共部分类时间更新3:第页
{
受保护的无效计时器1_刻度(对象发送方,事件参数e)
{
Label1.Text=“刷新时间为”+DateTime.Now.ToLongTimeString();
int sec=DateTime.Now.Second;
对于(int i=秒;i<秒+20;i++)
{
HtmlTableRow行=新的HtmlTableRow();
row.Attributes.Add(“onmouseover”,“style.backgroundColor=”#BFCBD6');
添加(“onmouseout”,“style.backgroundColor='white'”);
Add(“onmouseup”,“javascript:showMessage('row“+i+”)”);
事件。行。添加(行);
HtmlTableCell cell3=新的HtmlTableCell(“td”);
cell3.InnerText=“行-”+i;
行。单元格。添加(单元格3);
HtmlTableCell cell1=新的HtmlTableCell(“td”);
cell1.InnerText=“foo”;
row.Cells.Add(cell1);
HtmlTableCell cell2=新的HtmlTableCell(“td”);
cell2.InnerText=“poo”;
行。单元格。添加(单元格2);
}
}  
}
运行站点时,在Visual Studio中,我看到许多
脚本块
文件在
TimerUpdate3.aspx
文件下累积。它们中的每一个都包含
onmouseup
功能。这些文件一直累积到整个站点被卡住为止。
如果我注释掉将
onmouseup
属性添加到行中的行,那么一切都很好。

我在这里做错了什么?

如果去掉“javascript:”会发生什么?最后一件事-用String.Format(“window.alert({0}')”,I)替换该行如何,即:row.Attributes.Add(“onmouseup”,String.Format(“window.alert({0}')”,I));请注意,这可能也很有用:谢谢您的帮助。我必须调用一个JavaScript函数(上面的代码只是一个演示)。然而,该链接提供了大量信息。我仍然担心这个不断增长的“脚本块”条目列表没有被处理,并导致内存链接。
using System;  
using System.Web.UI;
using System.Web.UI.HtmlControls;

public partial class TimerUpdate3 : Page
{
  protected void Timer1_Tick(object sender, EventArgs e)
  {
    Label1.Text = "Refreshed at " + DateTime.Now.ToLongTimeString();
    int sec = DateTime.Now.Second;

    for (int i = sec ; i < sec + 20; i++)
    {
        HtmlTableRow row = new HtmlTableRow();
        row.Attributes.Add("onmouseover", "style.backgroundColor='#BFCBD6'");
        row.Attributes.Add("onmouseout", "style.backgroundColor='white'");
        row.Attributes.Add("onmouseup", "javascript:showMessage('row " + i + "')");
        Incidents.Rows.Add(row);

        HtmlTableCell cell3 = new HtmlTableCell("td");
        cell3.InnerText = "row - " + i;
        row.Cells.Add(cell3);

        HtmlTableCell cell1 = new HtmlTableCell("td");
        cell1.InnerText = "foo";
        row.Cells.Add(cell1);

        HtmlTableCell cell2 = new HtmlTableCell("td");
        cell2.InnerText = "poo";
        row.Cells.Add(cell2);
    }
  }  
}