Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2008-10-30
5
Medium Priority
?
4,015 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
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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
This article discusses how to implement server side field validation and display customized error messages to the client.
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Loops Section Overview

783 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