Click here to Skip to main content
15,886,110 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi everyone,

Does anyone know how to display real time timing(clock) on asp.net web page by using C# language? Previously, I have done the following code, but the code is written in Javascript and declared in HTML page. But now, I have to change it to C# language and call in page_load method. Is there any solution to do this?


function dTime()
{
var d = new Date();
var h = d.getHours();
var m = d.getMinutes();
var s = d.getSeconds();

//add a zero in front of numbers < 10
m = checkTime(m);
s = checkTime(s);

document.getElementById('txt').innerHTML = "Time: " + h + ":" + m + ":" + s;

t = setTimeout ('dTime()', 500);
}

function checkTime(i)
{

if (i < 10)
{
i= "0" + i;
}

return i;
}



Thanks.
Posted
Updated 22-Feb-10 17:16pm
v3

hai
Step 1: create one meta tag for refreshing page, that tag follows

Step 2: Create one label and assign following method
Label1.Text = System.DateTime.Now.ToString();
 
Share this answer
 
v2
Set the text in a label to the current time. Refresh the page every second. JavaScript is the better option though.
 
Share this answer
 
Chao90 wrote:
Does anyone know how to display real time timing(clock) on asp.net web page by using C# language?


The fact that you'd ask this, shows you know nothing about ASP.NET, what it is, or what it does. Keep using the code you have, and buy some ASP.NET books and read them.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900