Home > DeveloperSection > Forums > timer control not working in ascx page
Royce Roy
Royce Roy

Total Post:134

Posted on    April-10-2015 7:25 AM


 1 Reply(s)
 630  View(s)
Rate this:

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:UpdatePanel id="updPnl" runat="server" UpdateMode="Conditional"  ChildrenAsTriggers="TRUE">
<asp:AsyncPostBackTrigger ControlID="timer1" EventName="Tick"  />
  <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);
                timer1.Enabled = true;
        protected void timer1_tick(object sender, EventArgs e)
            if (0 > DateTime.Compare(DateTime.Now,
                lblTimer.Text = "Number of Minutes Left: " +

Mayank Tripathi
Mayank Tripathi

Total Post:397

Posted on    April-10-2015 8:01 AM

The timer references Timer1 but when the user control gets rendered it will have a newly assigned name because it is on a user control. Do a View Source and you will see this is the case

<asp:AsyncPostBackTrigger ControlID="timer1" EventName="Tick"  />

Add ClientIDMode="Static" as shown below. This assumes this control is only dropped on the page one time, otherwise you should set ControlID of timer1 postback triggers to Timer1.ClientID()


<asp:Timer ID="timer1"
ClientIDMode="Static" runat="server"
Interval="1000" OnTick="timer1_tick"></asp:Timer>

Don't want to miss updates? Please click the below button!

Follow MindStick