2012-01-05 119 views
0

我有這個問題相同的問題。 se the ClientScriptManager.RegisterForEventValidation method in order to register the postback or callback data for validation我還沒有與<%@ Page EnableEventValidation="false" %>。我任何問題,解決它,我嘗試無法解決Timer_Tick

protected void Timer1_Tick(object sender, EventArgs e) 
{ 
     Label2.Text = Convert.ToString((Convert.ToInt32(Label2.Text) - 1)); 
     if (Convert.ToInt32(Label2.Text) == 0) 
     { 

      Timer1.Dispose(); 
      Submit(); 
     } 
} 

代碼做工精細意味着submit()是工作,如果我從調用提交button.If其呼叫從Timer_Tick它不是work.And計時器沒有停止或處置。什麼是PLZ建議的問題?

定時器:

<asp:UpdatePanel ID="UpdatePanel1" runat="server"> 
          <ContentTemplate> 
           <asp:Timer ID="Timer1" runat="server" Interval="1000" ontick="Timer1_Tick"> 
           </asp:Timer> 
           <asp:Label ID="Label1" runat="server" Text="Remaining Time:(Min)"></asp:Label> 
           <asp:Label ID="Label2" runat="server" Text="100"></asp:Label> 
          </ContentTemplate> 
         </asp:UpdatePanel> 
+0

您可以在初始化定時器的位置顯示代碼嗎?我懷疑你有一些不太正確的東西。是否拋出任何異常?它是否激發過Timer_Tick方法? – 2012-01-05 17:04:28

+0

也在代碼中的位置是Timer1聲明它是什麼訪問級別.. – MethodMan 2012-01-05 17:05:21

回答

0
Label2.Text = Convert.ToString((Convert.ToInt32(Label2.Text) - 1)); 

是否該行工作?

也許如果

Convert.ToInt32(Label2.Text) == 0 

沒有返回true

+0

yap它的工作,這不是一個真正的問題:) – 2012-01-05 17:05:08

0

你在哪裏啓用或啓動頁面上的計時器?定時器不會在加載頁面時自動啓動,您需要明確調用Start()或設置Enabled = true