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

i need update message in asp.net C#

Updated Message should be less than 5 minutes system time.

suppose now the time is 10:55 am and the last updated message should me
like this last updated at 10:50 am

C#
protected void Timer2_Tick(object sender, EventArgs e)
    Label1.Text = "Last Updated at : " + DateTime.Now.ToLongTimeString();


Thanks
Posted

Hi,
You can use this:
C#
DateTime.Now.AddMinutes(-5);


Cheers
 
Share this answer
 
v2
Comments
Reza Ahmadi 25-Apr-12 4:31am    
What was the reason for that vote??
Hi,

You can use following code:

C#
protected void Timer2_Tick(object sender, EventArgs e)
{
    Label1.Text = "Last Updated at : " + DateTime.Now.AddMinutes(-5).ToLongTimeString();
}
 
Share this answer
 
v2
Set the timer interval on 5 minutes

ASP.NET
<asp:timer id="Timer1" ontick="Timer1_Tick" runat="server" interval="300000" xmlns:asp="#unknown" />


Then make the last update like

C#
protected void Timer2_Tick(object sender, EventArgs e)
    Label1.Text = "Last Updated at : " + DateTime.Now.AddMinutes(-5).ToLongTimeString();


EDIT:

To stop the timer:

C#
protected void Timer2_Tick(object sender, EventArgs e)
    Label1.Text = "Last Updated at : " + DateTime.Now.AddMinutes(-5).ToLongTimeString();
timer1.Enabled = false;


Cheers
 
Share this answer
 
v2
Comments
Syed SufiyanUddin 25-Apr-12 4:48am    
this is good, But this message should stay for 30 seconds and it should go.
Mario Majčica 25-Apr-12 4:51am    
Try setting the timer1.Enabled = false;

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