每秒在ASP.net头部创建一次Javascript,Ajax计时器会导致问题

每秒在ASP.net头部创建一次Javascript,Ajax计时器会导致问题,javascript,asp.net,vb.net,Javascript,Asp.net,Vb.net,我有一个简单的表单,它使用当前时间的计时器更新标签。我注意到,当代码运行时,它会在每个勾号的页面标题中添加以下内容 <script type="text/javascript">Sys.Application.add_init(function() { $create(Sys.UI._Timer, {"enabled":true,"interval":1000,"uniqueID":"Timer1"}, null, null, $get("Timer1")); }); <

我有一个简单的表单,它使用当前时间的计时器更新标签。我注意到,当代码运行时,它会在每个勾号的页面标题中添加以下内容

<script type="text/javascript">Sys.Application.add_init(function() {
    $create(Sys.UI._Timer, {"enabled":true,"interval":1000,"uniqueID":"Timer1"}, null, null, $get("Timer1"));
});
</script>
当我在Chrome中查看页面时,我看到了

将来对遇到此问题的任何人的引用


将计时器移到更新面板外。如果你需要一个更新面板内的计时器,那么下面将带你到那里

                    <script type="text/javascript">
                    window.onload = function () {
                        setInterval(function () {
                            document.getElementById("<%=Button7.ClientID %>").click();
            }, 1000);
                    };
    </script>

window.onload=函数(){
setInterval(函数(){
document.getElementById(“”)。单击();
}, 1000);
};

将计时器移到UpdatePanel之外。这将在每次更新UpdatePanel时停止重新添加计时器脚本

<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="WebForm4.aspx.vb" Inherits="A2Chat.WebForm4" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
        <div>
            <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>

            <asp:Timer ID="Timer1" runat="server" Interval="1000"></asp:Timer>

            <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional" ChildrenAsTriggers="False">
                <ContentTemplate>
                    <asp:Label id="Label1" runat="server" Text="test"></asp:Label>
                </ContentTemplate>
                <Triggers>
                    <asp:AsyncPostBackTrigger ControlID="Timer1" />
                </Triggers>
            </asp:UpdatePanel>
        </div>
    </form>
</body>
</html>

谢谢,但现在它会引起可怕的闪烁。这是一个开始。有什么建议吗?我的测试中没有闪烁,所以我只能猜测。请使用
句柄查看我的编辑
&
UpdatePanel1.Update()
                    <script type="text/javascript">
                    window.onload = function () {
                        setInterval(function () {
                            document.getElementById("<%=Button7.ClientID %>").click();
            }, 1000);
                    };
    </script>
<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="WebForm4.aspx.vb" Inherits="A2Chat.WebForm4" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
        <div>
            <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>

            <asp:Timer ID="Timer1" runat="server" Interval="1000"></asp:Timer>

            <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional" ChildrenAsTriggers="False">
                <ContentTemplate>
                    <asp:Label id="Label1" runat="server" Text="test"></asp:Label>
                </ContentTemplate>
                <Triggers>
                    <asp:AsyncPostBackTrigger ControlID="Timer1" />
                </Triggers>
            </asp:UpdatePanel>
        </div>
    </form>
</body>
</html>
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
    Label1.Text = Now()
    UpdatePanel1.Update()
End Sub