Question

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";
}
Was it helpful?

Solution 3

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>");

  }

OTHER TIPS

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";
             }

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);

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;
             }

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); 
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top