By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,835 Members | 1,909 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,835 IT Pros & Developers. It's quick & easy.

count down timer with ASP.NET

missshaikh
P: 43
Hi all,

i need the count down timer when button click the timer start and count down work on ASP.net

:(

i have one timer which is on JavaScript that run page onload . but i need the Button click my code is here...

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>timer</title>
<SCRIPT TYPE="text/javascript" LANGUAGE="JavaScript">
<!--

dateFuture = new Date(2007,10,12,18,43,48);

//nothing beyond this point
function GetCount(){

dateNow = new Date(); //grab current date
amount = dateFuture.getTime() - dateNow.getTime(); //calc milliseconds between dates
delete dateNow;

// time is already past
if(amount < 0){
document.getElementById('countbox').innerHTML="Now !";
}
// date is still good
else{
days=0;hours=0;mins=0;secs=0;out="";

amount = Math.floor(amount/1000);//kill the "milliseconds" so just secs

days=Math.floor(amount/86400);//days
amount=amount%86400;

hours=Math.floor(amount/3600);//hours
amount=amount%3600;

mins=Math.floor(amount/60);//minutes
amount=amount%60;

secs=Math.floor(amount);//seconds

if(days != 0){out += days +" day"+((days!=1)?"s":"")+", ";}
if(days != 0 || hours != 0){out += hours +" "+((hours!=1)?":":"")+" ";}
if(days != 0 || hours != 0 || mins != 0){out += mins +" "+((mins!=1)?" ":"")+", ";}
out += secs +" seconds";
document.getElementById('countbox').innerHTML=out;

setTimeout("GetCount()", 1000);
}
}

//window.onload=function(){GetCount();}//call when everything has loaded

//-->
</script>

</head>
<body>
<form id="form1" runat="server">

<div id="countbox" ></div>


<asp:Button ID="Button1" runat="server" Text="Start " OnClick="Button1_Click"/>

</body>
</html>


this is my code.

please friends Help me
Nov 12 '07 #1
Share this Question
Share on Google+
3 Replies


Shashi Sadasivan
Expert 100+
P: 1,435
Have you tried AJAX .Net components for this?
you can get more info on this as ajax.asp.net

cheers
Nov 12 '07 #2

missshaikh
P: 43
Have you tried AJAX .Net components for this?
you can get more info on this as ajax.asp.net

cheers
i can not use Ajax. on my online server where i upload my site there is no accessible for Ajax dll files
Nov 18 '07 #3

kenobewan
Expert 2.5K+
P: 4,871
This is a client side JS problem, its incidental that you are using asp.net. Normally this type of function called in onload event declared on the body tag. HTH.
Nov 18 '07 #4

Post your reply

Sign in to post your reply or Sign up for a free account.