Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2008-10-30
5
Medium Priority
?
3,934 Views
Last Modified: 2012-06-27
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?
0
Comment
Question by:CitySec
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 21

Expert Comment

by:silemone
ID: 22843325
i think you have to use the asp ajax controls to do this...there is a timer that you can use...there...
0
 
LVL 21

Expert Comment

by:silemone
ID: 22843402
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...
0
 
LVL 8

Accepted Solution

by:
tiagosalgado earned 2000 total points
ID: 22843405
You can use setTimeOut() javascript function to hide your label.
Above code, will set your label text and after 5 seconds the label will disappear.
 

<asp:ScriptManager runat="server" ID="sm1" />
        <asp:UpdatePanel runat="server" ID="up1">
            <ContentTemplate>
                <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
                <asp:Button ID="Button1" runat="server" Text="Button" />
            </ContentTemplate>
        </asp:UpdatePanel>
 
And at code-behing you can have something like this:
 
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
        Label1.Text = "my label text"
        ScriptManager.RegisterClientScriptBlock(Me.Page, Me.GetType, "script", "window.setTimeout(function() { document.getElementById('" + Label1.ClientID + "').style.display = 'none' },5000);", True)
    End Sub

Open in new window

0
 
LVL 13

Expert Comment

by:TechTiger007
ID: 22843413
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)
0
 
LVL 2

Author Comment

by:CitySec
ID: 22843483
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?
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

jQuery is a JavaScript library that greatly simplifies JavaScript programming. AJAX is an acronym formed from "Asynchronous JavaScript and XML."  AJAX refers to any communication between client and server, when the human client does not observe a…
The most up-to-date version of this article is on my Blog https://iconoun.com/blog/
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Suggested Courses

722 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question