【发布时间】:2013-12-27 22:56:20
【问题描述】:
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 秒运行一次。问题出在弹窗上,浏览器没有弹窗。
【问题讨论】:
-
不要使用更新面板。使用 jquery ajax 和 javascript settimout 页面不会刷新页面...
标签: javascript asp.net vb.net timer updatepanel