Timer控件和UpdatePanel控件中的javascript弹出窗口无法正常工作

时间:2013-12-27 22:56:20

标签: javascript asp.net vb.net timer updatepanel

MasterPage.master

<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
  <ContentTemplate>
    <asp:Timer ID="Timer1" runat="server" Interval="10000">
    </asp:Timer>
  </ContentTemplate>
</asp:UpdatePanel>



MasterPage.master.vb

Protected Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick

    'some sql select codes

    con.Open()
    Dim result As Integer = DirectCast(cmd.ExecuteScalar(), Int32) 'ExecuteScalar() only return 1 row and ignore rest
    con.Close()

    If result > 0 Then

        'Page.ClientScript.RegisterStartupScript(Me.GetType(), "AlertMessageBox", "alert('hello world');", True)
        'Page.ClientScript.RegisterStartupScript(Me.GetType(), "AlertMessageBox", "alert('" & result & " hello world');", True)
        ScriptManager.RegisterStartupScript(Me.UpdatePanel1, Me.UpdatePanel1.GetType(), "AlertMessageBox", "alert(‘hello world’);", True)


    End If

End Sub



基本上我有一个Timer控件在固定的时间间隔内运行SQL Select,如果result大于0,则会有一个弹出警报。

如果我不使用UpdatePanel但没有UpdatePanel,则代码正常工作,只要Timer控件运行,页面就会刷新,导致用户正在处理的任何内容迷路了。



编辑:进一步澄清

Timer1_Tick每隔10秒运行一次。问题在于弹出窗口,浏览器上没有弹出窗口。

1 个答案:

答案 0 :(得分:0)

OnTick="Timer1_Tick"添加到您的.master标记。

此外,您不需要,但您可以尝试添加:

<Triggers>
  <asp:AsyncPostBackTrigger ControlID="Timer1" EventName="Tick" />
</Triggers>
相关问题