Click here to Skip to main content
15,888,610 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi I have time in my page. I write it In page_load of codebehind . therefore it be shown static .
What shoul I do until it be repeat every second?
Thanks very much
Posted

Why Don't you use javascript, Javascript enable you to display currenttime in every second
XML
<script type="text/javascript">
    function ShowTime() {
        var dt = new Date();
        document.getElementById("<%= TextBox1.ClientID %>").value = dt.toLocaleTimeString();
        window.setTimeout("ShowTime()", 1000);
    }
</script>

<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>

<script type="text/javascript">
    // a startup script to put everything in motion
    window.setTimeout("ShowTime()", 1000);
</script>


For other References Try Counting Time on Page with AJAX in ASP.NET[^]
 
Share this answer
 
v2
You should not be writing your time logic in page load.
Infact, AS.Net is a server side framework so you should be using JavaScript to do this.
Start with this[^].
 
Share this answer
 
Comments
armm1388 28-May-11 23:59pm    
but i want to user show time of server no time of his client
You should do it in javascript, however when you take time or date through javascript, it is user specific.
user's machine date time may be wrong and you should not rely on that.

you should take current time through server script
System.DateTime.Now()
on pageLoad, and write a function in javascript to increment it every second.

Hope you got the logic.
 
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