Reputation: 969
What is the best way to show a label
(containing text = saved successfully) after saving data to only be visible (visible = true) and then disappear (become visible = false) after say 2 seconds? I have seen people use timers before but cant get them to work.
if (saved == true)
{
//data saved - show label and then make visible = false
lblsuccess.Visible = true;
lblsuccess.Text = "Visit saved";
}
Upvotes: 1
Views: 11457
Reputation: 161
Use This one line code in CS
Set by default label Visibility= False;
ScriptManager.RegisterClientScriptBlock (this.Page, typeof (Page ), "script" , "window.setTimeout(function() { document.getElementById('" + lblSubMsg.ClientID + "').style.display = 'none' },2000);", true);
Upvotes: 2
Reputation: 969
Found this and it did the trick for me! Thanks for your answers above though
if (saved == true)
{
lblsuccess.Visible = true;
lblsuccess.Text = "Visit saved";
ClientScript.RegisterStartupScript(this.GetType(), "HideLabel", "<script type=\"text/javascript\">setTimeout(\"document.getElementById('" + lblsuccess.ClientID + "').style.display='none'\",2000)</script>");
}
Upvotes: 1
Reputation: 17614
you need to do it by java-script jquery delay function as follows
Note that the delay is an integer indicating the number of milliseconds to delay execution of the next item in the queue.
In doucment.ready
function of jquery you can write
$("#lblsuccess").delay(3200).fadeOut(300);
or you want to use client id then
$("#<%=lblsuccess.ClientID %>")..delay(3200).fadeOut(300);
Upvotes: 0
Reputation: 14389
System.Timers.Timer timer1;
timer1 = new System.Timers.Timer(2000);
timer1.Enabled=false;
timer1.Elapsed += new ElapsedEventHandler(timer1_Elapsed);
void timer1_Elapsed(object sender, ElapsedEventArgs e)
{
lblsuccess.Visible = false;
timer1.Enabled=false;
}
if (saved == true)
{
//data saved - show label and then make visible = false
timer1.Enabled=true;
lblsuccess.Visible = true;
lblsuccess.Text = "Visit saved";
}
Upvotes: 2
Reputation: 790
Try this :
if (saved == true)
{
//data saved - show label and then make visible = false
lblsuccess.Visible = true;
lblsuccess.Text = "Visit saved";
System.Threading.Thread.Sleep(2000);
lblsuccess.Visible= false;
}
Upvotes: 0