簡體   English   中英

計時器控件和UpdatePanel控件中的javascript彈出窗口不起作用

[英]javascript popup in Timer control and UpdatePanel control not working

母版頁

<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秒運行一次。 問題在於彈出窗口,瀏覽器上沒有彈出窗口。

添加OnTick="Timer1_Tick".master標記。

另外,您不需要,但是您可以嘗試添加:

<Triggers>
  <asp:AsyncPostBackTrigger ControlID="Timer1" EventName="Tick" />
</Triggers>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM