Friday, 29 July 2016

Hide Label Tag after some seconds(3 Second) in ASP.NET

Add below java script in .aspx page

 <script type="text/javascript">
        function HideLabelText() {
            var _Second = 3; // Specify duration in second
            setTimeout(function () {
                document.getElementById("<%=lblMessage.ClientID %>").style.display = "none";
            }, _Second * 1000); 
        };
  </script>
 
  lblMessage is a ID of Label control
  _Second = 3 i.e It will hide label after 3 seconds , you can change this as per your need.

Add below lines in the event handler in your code.

C#.NET : ClientScript.RegisterStartupScript(this.GetType(), "alert", "HideLabelText();", true); 
VB.NET : ClientScript.RegisterStartupScript(Me.[GetType](), "alert", "HideLabelText();", True)