I am assigning some text to Label after button click as follows:
protected void Button1_Click(object sender, EventArgs e)
{
Label1.Text = "Hello";
}
After some amount of time, say 30seconds, I would like to clear the Label text.
Can any one help me?
I tried the following script, but it doesn’t work for me.
$(document).ready(function() {
$('#Label1').fadeOut(3000, function() {
$(this).html(""); //reset the label after fadeout
});
});
My design
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script type="text/javascript">
$(document).ready(function() {
$('#<%= myLabel.ClientID %>').fadeOut(3000, function() {
$(this).html(""); //reset the label after fadeout
});
});
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label id="myLabel" runat="server"></asp:Label>
<asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" />
</div>
</form>
</body>
</html>
In order to run some code after specified time you need to wrap the code in ready handler in
call. What you are doing is fading out immediately over a 3 seconds time. 3000ms that you are passing is parameter to fadeOut function telling it how long fading out should take.
Here you have working example:
http://jsfiddle.net/VPrEZ/3/
Note that in case of ASP.NET app you should use:
to select label. That is because you don’t know the id of the control until runtime when control has runat=”server” attribute set.