Click here to Skip to main content
15,911,035 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
hello friends

i want to hide label message after few minute automatically.
here is my code but its cant work.
in aspx page
XML
<script type="text/javascript" language="javascript">
            $("#lblmsg").delay(5000).fadeOut(100);
        </script>
<asp:Label ID="lblmsg" runat="server" Visible="false">   


or in .cs page

C#
protected void btnSubmit_Click(object sender, EventArgs e)
{
          if (cityList.Count != 0)
          {
              lblmsg.Visible = true;
              lblmsg.Text = "YES! COD payment option is available for this Pincode";
              lblmsg.Attributes.Add("style", "color:Green;");
          }
}

but is not hide the label..
please help me or give some other method to do this..
Thank You to all...
Posted
Updated 1-Jun-12 0:59am
v2

Read this

ASP.NET Hide Controls after number of seconds[^]


Hope this helps , If yes then plz accept and vote the answer. Any queries / questions on this are always welcome.

Thanks & Regards
RDBurmon.Sr.Software Engineer
 
Share this answer
 
Comments
Yatin_Chauhan 1-Jun-12 7:59am    
lblmsg.Text = "YES! COD payment option is available for this Pincode";
lblmsg.Attributes.Add("style", "color:Green;");
ClientScript.RegisterStartupScript(this.GetType(), "HideLabel", "<script type=\"text/javascript\">setTimeout(\"document.getElementById('" + lblmsg.ClientID + "').style.display='none'\",5000)</script>");
Server-side IDs and IDs in the Javascript are not the same. You need to use the ClientID when constructing that JavaScript snippet:

<script type="text/javascript" language="javascript">
            $("<%=lblmsg.ClientID%>").delay(5000).fadeOut(100);
        </script>


Or you can set ClientIDMode to Static.

Also, that JS code looks like jQuery – have you included jQuery in your deployment and linked to it with a script tag? It is not just hiding the label, it is setting a timer and then applying a fade effect.

To hide a control you do:
XML
<script type="text/javascript" language="javascript">
 document.getElementById("<%=lblmsg.ClientID%>").style.display = 'none';
</script>
 
Share this answer
 
Comments
Yatin_Chauhan 1-Jun-12 8:00am    
lblmsg.Text = "YES! COD payment option is available for this Pincode";
lblmsg.Attributes.Add("style", "color:Green;");
ClientScript.RegisterStartupScript(this.GetType(), "HideLabel", "<script type=\"text/javascript\">setTimeout(\"document.getElementById('" + lblmsg.ClientID + "').style.display='none'\",5000)</script>");


now working this too.....
 
Share this answer
 
<script type="text/javascript" language="javascript">

            $("#lblError").delay(5000).fadeOut(100);

</script>

<asp:label id="lblError" runat="server" visible="false" xmlns:asp="#unknown">
</asp:label>
 
Share this answer
 
v2
use set timeout funtion to hide this label and use like this
after showing data in label now add this script it will automatically blank the text of lable.

C#
string sScript = "var t=setTimeout(hidelbl("+ lblmsg.clientid +"),5000);function hidelbl(lbl){lbl.vale='';clearTimeout(t););}";

                    ScriptManager.RegisterStartupScript(GetType(), "Script1", sScript, true);
 
Share this answer
 
Comments
Yatin_Chauhan 1-Jun-12 10:39am    
hello prosan sir.
there was error in scriptmanager it doesn't take 4 argument.
window.onload = function () {
var seconds = 5;
setTimeout(function () {
document.getElementById("&lt;%=lblMessage.ClientID %&gt;").style.display = "none";
}, seconds * 1000);
};





Add this in header part.. It works..
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900