ASP.NET - timer event - Asked By hiren dhameliya on 14-Apr-10 02:35 AM

how i can  use timer in my application 
 x= 40 
 timer will  start  0  to 40 second plz reply me as soon as 
with coding exmple
 some explian plz
Santhosh N replied to hiren dhameliya on 14-Apr-10 02:39 AM
There is no timer control in and alternatively you can rely on client side scripts for this...
you can check here for a sample code in client side javascript..
Anand Malli replied to hiren dhameliya on 14-Apr-10 02:55 AM
hi hiren

you can surely use timer at server side aith the help of SCRIPTMANAGER,UPDATEPANEL and TIMER control

put script manager on to your page under that take update panel and in that take timer control provided in toolbox

so your code would be something like below

public partial class _Default : System.Web.UI.Page 
    protected void Timer1_Tick(object sender, EventArgs e)
        Label1.Text = "Timer: " +timerVar;

its easy right...

alternatively client side script is always there,you can use setTimeout or setInterval function for that

Anoop S replied to hiren dhameliya on 14-Apr-10 03:00 AM
You can use Ajax timer control with,

eg for 40sec

<html dir="ltr" xmlns="<a rel="nofollow" target="_new" href="">">"></a>

<script runat="server">

Protected Sub Timer1_Tick(ByVal sender As Object, ByVal e As System.EventArgs)


End Sub



<form id="form1" runat="server">

<h1>Submission successful!</h1>

Thank you for your submission

If you are not redirected in 40 seconds, click <asp:HyperLink runat="server" ID="lnkredirect" NavigateUrl="~/Default.aspx" Text="here"></asp:HyperLink>

<asp:ScriptManager ID="ScriptManager1" runat="server">


<asp:Timer ID="Timer1" runat="server" EnableViewState="false" Interval="5000" OnTick="Timer1_Tick">





you can read more from here
Web Star replied to hiren dhameliya on 14-Apr-10 03:23 AM
u just put timer control on page and than u implement these code in code behind file
protected System.Timers.Timer timer1;
private int test;

protected void Page_Load(object sender, System.EventArgs e)
// Put user code to initialize the page here
test = 1;

timer1.Interval = 4000;

timer1.Enabled = true;


private void timer1_Elapsed(object sender, System.Timers.ElapsedEventArgs e)

test = test+1;

lblCounter.Text = "count:"+test;


In C# the 'timer1.enabled' method calls the 'timer1_Tick' which, as far as i know, is the same as the Elapsed method above.

Many thanks!!!!