Shubham Bhewanewala Shubham Bhewanewala - 3 months ago 51
ASP.NET (C#) Question

Timers Tick event not firing

There is a simple code in which I added a timer and generated tick event but the event is not firing.

<asp:Timer ID="Timer1" runat="server" Interval="1000" OnTick="Timer1_Tick" Enabled="True" EnableViewState="True" ViewStateMode="Inherit" ClientIDMode="Inherit"></asp:Timer>



protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
setImageurl();
//Timer1.Tick += new EventHandler(Timer1_Tick);
//Timer1.Interval = 1000;
}
}
void setImageurl()
{
Random _rand = new Random();
int i = _rand.Next(1, 4);
Image1.ImageUrl = "~/ImagesSlideshow/" + i.ToString() + ".jpg";
}
protected void Timer1_Tick(object sender, EventArgs e)
{
setImageurl();
}


I dont know why this is happening. Help me out.

Answer

Set EnableCdn="true" on the ScriptManager and it will work, just tried it on my side:

<form id="form1" runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server" EnableCdn="true"></asp:ScriptManager>
    <asp:Timer ID="Timer1" runat="server" OnTick="Timer1_Tick" Interval="1000"></asp:Timer>
    <asp:Image ID="Image1" runat="server" />
</form>