Who is online? 128 guests and 0 members
Member login | Become a member
Posted: 11/28/2009 9:18:58 AM
I have a textbox in asp.net page i want to show clock continiously in that textbox.
Posted: 11/29/2009 11:51:46 AM
In ASPX
<html xmlns="http://www.w3.org/1999/xhtml"> <head id="Head1" runat="server"> <title></title> </head> <body> <form runat="server"> <asp:TextBox ID="txtClock" runat="server" style="width:400px;"></asp:TextBox> </form> </body> <script type="text/javascript"> //Users time var timeLocal = new Date(); //Calculate the difference (returns milliseconds) millDiff = timeLocal - timeServer; //initalize the clock on loading of page window.onload = function() { //set the interval so clock ticks var timeClock = setInterval('TimeTick()', 10); } //The ticking clock function function TimeTick() { //grab updated time timeLocal = new Date(); //add time difference timeLocal.setMilliseconds(timeLocal.getMilliseconds() - millDiff); //display the value document.getElementById('<%= txtClock.ClientID %>').value = timeLocal; } </script> </html>
In Codebehind:
using System; namespace TestProject { public partial class Test : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { Response.Write(string.Format("<script>var timeServer = new Date('{0}');</script>", DateTime.Now)); } } }