You must Sign In to post a response.
  • Category: ASP.NET

    How to start timer on button click ?


    Are you looking for a way to start timer on button click ? then read this thread to know more about it



    Hello,
    I have simple timer of 10 minutes. But it creates a problem. Whenever i click on button, the timer starts again from starting. It is not properly working. the project is of online examniation system

    Help me out
  • #743963
    hi,

    Before starting the timer on the button click.
    Check the state of timer if the timer is stop then start it.
    Else do nothing.

    Hope this helps you

    Regards
    Shalini

  • #743983
    Hi,

    The problem could be coming due to Button click is posting back which is causing the Time to restart everytime.

    You keep the Timer in a UpdatePanel and keep the update mode as Conditional as shown so that it will start <asp:UpdatePanel runat="server" UpdateMode="Conditional">

  • #743998
    Hai Rutul,
    I think its better to use the JavaScript for the timer part as it will improve the response time of the application.
    You can start the timer on the bodyload of the form.
    See below fothe refernce link toimplement it:
    http://www.codeproject.com/Questions/258404/Countdown-Timer-using-Javascript

    Hope it will be helpful to you.

    Regards,
    Pawan Awasthi(DNS MVM)
    +91 8123489140 (whatsApp), +60 14365 1476(Malaysia)
    pawansoftit@gmail.com

  • #744016
    Dear Padmasri Vemuri

    I have already kept timer in update panel with update mode as conditional
    still it is not working

  • #744046
    Hi..

    Go through the below mentioned links.. This may help u lot..

    1.http://www.aspdotnet-suresh.com/2013/02/start-and-stop-timer-in-javascript.html

    2.http://forums.asp.net/t/1929881.aspx?How+to+Start+a+Timer+on+button+click+in+asp+net+get+alert+window+pop+up+after+2+hrs+

    3.http://stackoverflow.com/questions/18282260/run-timer-for-10-minutes-and-then-disable-button-c-sharp

    4.http://www.daniweb.com/web-development/aspnet/threads/426550/start-timer-on-button-click

  • #744059

    protected void Button1_Click(object sender, EventArgs e)
    {
    System.Timers.Timer _timer;
    _timer = new System.Timers.Timer(10000);
    _timer.Elapsed += new ElapsedEventHandler(_timer_Elapsed);
    _timer.Enabled = true;
    }

    Thanks & Regards
    Anil Kumar Pandey
    Microsoft MVP, DNS MVM


  • Sign In to post your comments