Click here to Skip to main content
15,893,594 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I simply use a label in my asp.net app to display messgaes..

how to clear the messages after a specific time delay..


say after 1sec 200 ms , the message should get auto cleared..

in the sense lablel.Text="";
Posted
Comments
Member 10468587 21-Dec-13 3:02am    
i just need it in c# not in jscript..

and should be short and sweet
♥…ЯҠ…♥ 21-Dec-13 3:07am    
with button click event or in which event you want to clear?

1 solution

Hi,

You could use System.Threading to do it.
Its very simple and its very sweet too ;-)

Add namespace to your project like
C#
using System.Threading;

If you want to clear it in Button Click event then use the below code
C#
protected void Button1_Click(object sender, EventArgs e)
       {
           Thread.Sleep(1200); //Delay for 1200 milliseconds.
           Label1.Text = "";
       }

Hope this helps you a bit.

Regards,
RK
 
Share this answer
 
v3
Comments
Member 10468587 21-Dec-13 3:57am    
does it delay all the statements execution or the statement below it


in a event
Member 10468587 21-Dec-13 4:04am    
protected void Btnclear_Click(object sender, EventArgs e)
{
Thread.Sleep(10);
lblmessage.Text = "";
BtnUpdate.Visible = false;
BtnSave.Visible = true;
clear();
}


its not working..
♥…ЯҠ…♥ 21-Dec-13 4:33am    
How many seconds you want to delay? 10 milliseconds is too low for delay atleast try to give 1000 instead of 10
Member 10468587 21-Dec-13 7:04am    
i had given 1000 earlier but the msg is not gettin cleared...


i just kept on reducing the value...

in order to check it
but even for 10 ms its not getting cleared
♥…ЯҠ…♥ 21-Dec-13 7:18am    
Why?You get any error? Here its working fine, clearing after 1.2 Secs

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