Click here to Skip to main content
16,019,043 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear All,

I am building an ASP.net Webpage and I want to show the current time on real basis.
I am using a Timer for the same.
My code for timer is :-

HTML
<asp:ScriptManager ID = "ScriptManager1"  runat="server">
</asp:ScriptManager>
<asp:Timer ID="Timer1" runat="server" Interval="100" OnTick="Timer1_Tick">
</asp:Timer>
<asp:Label ID = "lblTime" runat="server" Font-Bold="True" Font-Names="Cambria" Font-Size="Small" ForeColor="Lime"></asp:Label>
</td>
</tr>


and the code behind the timer is :-

C#
protected void Timer1_Tick(object sender, EventArgs e)
 {
     lblTime.Text = "Current Time : " + System.DateTime.Now.ToShortTimeString();
 }


When I try to do the same thing in an Windows Application, it works perfect..
Kindly help me with the solution for the same..

Thank you.
Posted

Hi,
I found the solution.
Below is the link for the same.

http://www.w3schools.com/js/tryit.asp?filename=tryjs_time[^][^]

Thanks :-)
 
Share this answer
 
XML
You can use following code for this...
between <head>....</head> tag put

<% Response.AddHeader("Refresh", "timeinseconds") %>  OR
<% Response.AddHeader("Refresh", "1") %>
and on page_load  assign
lable.text = DateTime.Now().Tostring("TimeFormate");

Or You can also use Ajax Timer control for this.
 
Share this answer
 
Comments
Vreeti 19-Mar-13 3:36am    
Hi Rohit,
I don't want to refresh the page, I want to refresh the time lable only.. And I am using the Ajax Timer.. But it is not working...
Rohit Kumar Mumbai 19-Mar-13 4:26am    
Please follow the steps mentioned in the below link :-

http://www.asp.net/ajax/documentation/live/tutorials/intrototimercontrol.aspx

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