Introduction

Open Visual Studio and create a new project and select the Web template from the list and select ASP.NET Empty Web Application. Enter the name of your application and click on OK.
Right-click on the project and select Add -> Web Form and name it as Home.aspx.
Now Drag and drop one TextBox, a Button, and a Label on the Home.aspx page.
Paste the following JavaScript function in the head section of the Home.aspx page.
  1. <script type="text/javascript">
  2. window.onload = function ()
  3. {
  4. var seconds = 5;
  5. setTimeout(function () {
  6. document.getElementById("<%=displaymessage.ClientID %>").style.display = "none";
  7. }, seconds * 1000);
  8. };
  9. </script>
Here I am hiding the Label after 5 seconds.
Below is the code to make the label visible when Submit Form button is clicked.
  1. protected void OnClickSubmitButton(object sender, EventArgs e)
  2. {
  3. displaymessage.Visible = true;
  4. }
ASPX Page Code
  1. <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Home.aspx.cs" Inherits="HideLabelAutomatically.Home" %>
  2. <!DOCTYPE html>
  3. <html xmlns="http://www.w3.org/1999/xhtml">
  4. <head runat="server">
  5. <title>HideLabelAutomatically</title>
  6. <script type="text/javascript">
  7. window.onload = function ()
  8. {
  9. var seconds = 5;
  10. setTimeout(function () {
  11. document.getElementById("<%=displaymessage.ClientID %>").style.display = "none";
  12. }, seconds * 1000);
  13. };
  14. </script>
  15. </head>
  16. <body>
  17. <form id="form1" runat="server">
  18. <div>
  19. Enter Name:
  20. <asp:TextBox ID="Name" runat="server" />
  21. <br />
  22. <br />
  23. <asp:Button ID="submitbutton" Text="Submit Form" runat="server" OnClick="OnClickSubmitButton" />
  24. <br />
  25. <br />
  26. <asp:Label ID="displaymessage" ForeColor="Green" Font-Bold="true" Text="Form has been submitted successfully." runat="server" Visible="false" />
  27. </div>
  28. </form>
  29. </body>
  30. </html>
Output