2
我使用一個計時器來遞增變量計數計時器不遞增在計時器滴答可變
在前面我使用定時器的UpdatePanel更新只是一個modalpopupextender這樣
<asp:Timer runat="server" id="Timer2" Interval="1000" OnTick="Timer2_Tick" Enabled ="false"> </asp:Timer>
<asp:UpdatePanel runat="server" id="UpdatePanel1">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="Timer2" EventName="Tick" />
</Triggers>
<ContentTemplate>
<div id="Pingdialog">
<asp:Panel ID="pn1" runat="server" Style="display: none; background-color:White; border: solid 1px silver;" >
<asp:Panel ID="pn2" runat="server" Style="cursor: move; background-color: silver;
border: solid 1px Gray; color: Black; width:300px;" >
<div style="width:100%;" >BizView : </div>
</asp:Panel>
<div style="text-align:center; width:100%; margin-top:20px; font-size:18px; ">
<asp:Label ID="lblpingmes" runat="server" Text=""></asp:Label>
<asp:textbox ID="txtpingmes" runat="server" Text="" TextMode="multiline" AutoPostBack="true" Visible="false"></asp:textbox>
<p style="text-align: center;">
<asp:Button ID="Button1" runat="server" Text="OK" Width="100px" />
</p>
</div>
</asp:Panel>
<div style="display: none;"><asp:Button ID="Button2" runat="server" Text="." /></div>
<asp:ModalPopupExtender ID="modalping" runat="server" TargetControlID="button2"
PopupControlID="pn1" BackgroundCssClass="modalBackground" OkControlID="Button1"
OnOkScript="onOk()" DropShadow="true" PopupDragHandleControlID="SubPopup" BehaviorID="savepingmodal" />
</div>
</ContentTemplate>
</asp:UpdatePanel>
在後面的代碼
我使用BTN到enabled
定時器事件
Partial Class
Dim countpingcheck As integer
Protected Sub btnPing_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnPingATM.Click
pinglog(lblIP.Text.Trim)
modalping.Show()
Timer2.Enabled = True
End Sub
那麼當計時器開始做
Public Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick
countpingcheck += 1
modalping.Show()
If countpingcheck < 5 Then
lblpingmes.Text = countpingcheck
Else
Timer2.Enabled = False
checkip()
End If
End Sub
我有一個變量countpingcheck
將遞增+1每個時鐘週期,但它停留在數= 2
我不知道爲什麼,那我就調試它的循環只是0,1, 2
請記住,每個帖子後面都會創建一個新的頁面實例,所以'countpingcheck'將每個tick復位爲0,除非您以某種方式將其值保存在頁面上。 –
最好的方法是爲每個會話使用計時器實例。一旦會話結束,也配置定時器對象。如果你需要的細節讓我知道。 – vendettamit
謝謝@AJRichardson我遵循你的建議,我通過從'昏暗'改爲'共享'解決了它,它的工作! –