Link to home
Start Free TrialLog in
Avatar of CitySec
CitySec

asked on

How to make a label disappear after a certain length of time?

I have an asp.net label control which displays messages when users do certain operations on my page. This label control is set to visible="false" until it needs to be displayed, and then programmatically it's visibility is set to "true". When this happens, I don't want it to stay there, I want it to disappear after 5 seconds. What's the best way to do this? Is there an AJAX control that already does this, or do I need some custom Javascript? And if it is Javascript that I need, how do I get the function to fire every time the label's visibility is set to true?
Avatar of silemone
silemone
Flag of United States of America image

i think you have to use the asp ajax controls to do this...there is a timer that you can use...there...
oops...it's not part of the asp ajax control...It's the UpdateProgress...I'm thinking that if you set it for 5 seconds, then you can cause another event to happen after its finished...say:  have an event in you page called makeInvisible().  in the makeInvisible call a <asp:button.....style="display:none;"> button which will make label invisible...now, it's important that the label be placed inside of a UpdatePanel and the trigger for that updatePanel be that invisible button...
ASKER CERTIFIED SOLUTION
Avatar of tiagosalgado
tiagosalgado
Flag of Portugal image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Toms Edison
you can hide the label using javascript

add this code after you make label visible in code behind file
ClientScript.RegisterStartupScript("HideLabel()",<time in milliseconds>,true);

//add this function to the page
function HideLabel()
{
document.getElementById("LabelID").style = "display:none";
}

(there could be syntax error)
Avatar of CitySec
CitySec

ASKER

That was the first solution I tried because it was the easiest to paste and required only one line of code. The other solutions may work too, but I didn't try them. One last question, can I make the label fade out instead of disappear at once?