forum

Home / DeveloperSection / Forums / timer control not working in ascx page

timer control not working in ascx page

Royce Roy 1707 10-Apr-2015

it works in aspx page but does not fire in ascx control. here is the code of ascx. Please let me know what I am missing. All the remaining controls fire but the timer does not fire in my aspx page:

<asp:ScriptManager ID= "SM1"
runat="server" EnablePartialRendering="true">
</asp:ScriptManager>
<asp:UpdatePanel id="updPnl" runat="server" UpdateMode="Conditional"  ChildrenAsTriggers="TRUE">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="timer1" EventName="Tick"  />
 
</Triggers>
<ContentTemplate>
  <asp:Timer ID="timer1" runat="server" Interval="1000" OnTick="timer1_tick"></asp:Timer>
    <asp:Label ID="lblTimer" runat="server" Interval="1000" Enabled="False"></asp:Label>
 
 protected void Page_Load(object sender, EventArgs e)
        {
 if (!SM1.IsInAsyncPostBack)
                Session["timeout"] = DateTime.Now.AddMinutes(5).ToString();
            if (!IsPostBack)
            {
                //ScriptManager.RegisterStartupScript(this, this.GetType(), "test", "javascript:f1();", true);
                fillQuestionsLabel();
 
                timer1.Enabled = true;
            }
 
        }
        protected void timer1_tick(object sender, EventArgs e)
        {
            if (0 > DateTime.Compare(DateTime.Now,
           DateTime.Parse(Session["timeout"].ToString())))
            {
                lblTimer.Text = "Number of Minutes Left: " +
                ((Int32)DateTime.Parse(Session["timeout"].
                ToString()).Subtract(DateTime.Now).TotalMinutes).ToString();
            }
        }


Updated on 10-Apr-2015

Can you answer this question?


Answer

1 Answers

Liked By