I want to create counter in Asp.Net.
How should I create a counter?
It should be like a counter in a game where you have 4-5 minutes and need to complete a task and the counter moves in a descending order that it starts from 4 minues and ends with 00.
Brijendra GautamPosted Mar 24, 2014, 11:09 PM
Instead I suggest use the javascript or JQuery to count and update the timer and when timer comes to zero then raise a server side event to stop the game.
Below is the script:
var count = 5;
$(document).ready(function () {
var timerVal = $('#lblMessage').text();
if (timerVal != 'Counter finished') {
$('#counter').text(count);
window.setTimeout(timer, 1000);
}
});
function timer() {
$('#counter').text(count);
if (count == 0) {
__doPostBack('LinkButton1', '')
}
else {
count--;
window.setTimeout(timer, 1000);
}
}
And HTML
Hope this will help you.