Timer in c#.net

22/03/2012 17:30

 

                                         <asp:ScriptManager ID="ScriptManager1" runat="server" />
                                            <asp:UpdatePanel ID="UpdatePanel1" runat="server">
                                                <ContentTemplate>
                                                    <asp:Timer ID="Timer1" runat="server" Interval="1000" OnTick="Timer1_Tick">
                                                    </asp:Timer>
                                                 <asp:Label ID="lblTime" runat="server"></asp:Label>
                                                </ContentTemplate>
                                            </asp:UpdatePanel>
 
 
 
 private void RemainingTime(int seconds)
        {
           Session["time"] = DateTime.Now.AddSeconds(seconds);
        }
 
        protected void Timer1_Tick(object sender, EventArgs e)
        {
            if (ViewState["time"] != null)
            {
                TimeSpan time1 = new TimeSpan();
                time1 = (DateTime)ViewState["time"] - DateTime.Now;
                if (time1.Seconds <= 0)
                {
                    lblTime.Text = "TimeOut!";
                    RadioButtonList1.Enabled = false;
                }
                else
                {
                    lblTime.Text = time1.Seconds.ToString();
                }
            }
        }