How to show the running time on the .aspx page ?
which should be run consecutively ?
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Munesh SharmaPosted Aug 5, 2015, 3:17 AM
Amitesh VermaPosted Aug 5, 2015, 3:05 AM
var d = new Date(2011,8,22,13,0,0,0);
//func that transforms miliseconds in digital clock format i.e. 22:34:12
function transformMiliseconds(t){
var h = Math.floor((t/(1000*60*60))%24);
var m = Math.floor((t/(1000*60))%60);
var s = Math.floor((t/1000)%60);
h = (h <10)?'0'+h:h;
m = (m <10)?'0'+m:m;
s = (s <10)?'0'+s:s;
return h+':'+m+':'+s;
}
//ticker function that will refresh our display every second
function tick(){
var newd = new Date();
document.getElementById('time_ticker').innerHTML = transformMiliseconds(newd-d);
}
//the runner
Rajeesh MenothPosted Aug 5, 2015, 3:02 AM
You can Add a timer control and specify it for 1000 millisecond interval
Upendra Pratap ShahiPosted Aug 5, 2015, 2:49 AM
Upendra Pratap ShahiPosted Aug 5, 2015, 2:40 AM
Use below code -
{
}
Design Page-
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="ServerClock.aspx.cs" Inherits="ServerClock" %>
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 id="Head1" runat="server">
<title>Server Timetitle>
<script type="text/javascript">
function GetTime() {
CallServer(null, null);
}
function ReceiveServerData(rValue) {
objId = document.getElementById("clock");
objId.innerHTML = rValue;
setTimeout("GetTime()", 1000);
}
script>
head>
<body onload="GetTime()">
<form id="form2" runat="server">
<div>
<div id="clock">div>
div>
form>
body>
html>
Code behind page-
using System;
using System.Web;
using System.Web.UI;
public partial class ServerClock : System.Web.UI.Page, System.Web.UI.ICallbackEventHandler
{
public string returnValue;
protected void Page_Load(object sender, EventArgs e)
{
String cbReference = Page.ClientScript.GetCallbackEventReference
(this, "arg", "ReceiveServerData", "context");
String callbackScript = "function CallServer(arg, context)" +
"{ " + cbReference + "} ;";
Page.ClientScript.RegisterClientScriptBlock(this.GetType(),
"CallServer", callbackScript, true);
}
public void RaiseCallbackEvent(String eventArgument)
{
returnValue = DateTime.Now.ToLongTimeString();
}
public string GetCallbackResult()
{
return returnValue;
}
}