tags:

views:

165

answers:

4

Hi I'm new to c# programming language, I'm making an app regarding online exam through paging, in which I want to show the time limit for the user and it decrease as the time passes & goes to next question when the time reaches 0. I have done wd d portion wn d control goes to next question but I don't know how I'll show the time limit for question.

thanks in advance

+1  A: 

Search for "ASP.NET Countdown timer". Tons of results, feel free to choose the one that suits you best.

Cerebrus
FYI, I did the link to google thing once and got horribly downvoted. I don't see much wrong with it if it works, but I'm letting you know
Jacob Adams
I am aware of the proclivity of many users to downvote google links because it isn't really an answer (usually). However, in this case, I believe it presents the OP with more (and mature) options than anyone can do with sample code. However, your concern is much appreciated. :-)
Cerebrus
A: 

First add a label and timer to a form :

timer Properties :
this.timer1.Enabled = true;
this.timer1.Interval = 1000;
this.timer1.Tick += new System.EventHandler(this.timer1_Tick);

declare this globally :
private int hh;
private int mm;
private int ss;

In form_Load event add :

private void Form1_Load(object sender, EventArgs e) { int hours = 360 / 60; int minutes = 360 % 60;

        hh = hours;
        mm = minutes;
        ss = 59;

}

In timer_tick event add this code:

        String Hours;
        String Minutes;
        String Seconds;
        ss = ss - 1;

        Hours = (hh < 10) ? "0" + hh.ToString() : hh.ToString();
        Minutes = (mm < 10) ? "0" + mm.ToString() : mm.ToString();
        Seconds = (ss < 10) ? "0" + ss.ToString() : ss.ToString();
        label1.Text = Hours + " : " + Minutes + " : " + Seconds;

        if (Seconds == "00" && Minutes == "00" && Hours == "00")
        {
            timer1.Enabled = false;
            this.Enabled = false;
            Application.Exit();
        }
        if (ss == 0 && mm == 0)
        {
            ss = 60;
            mm = 59;
            hh = hh - 1;
        }
Girish1984
A: 

It seems really resource intensive to go back to the server every second. I would recommend doing something in javascript and using the SetTimeout call. If you're that bent of using managed code though, put a little Silverlight control in the page that has a timer and updated the dom every second.

Jacob Adams
A: 

However you implement the timer, place the countdown display (a label, etc.) inside of an Ajax UpdatePanel control. That way the countdown display can be updated continuously without updating the entire page.

Mark Maslar