Categories
Asp, Asp.net

Hide Label Automatically After Some Seconds Using JavaScript

Hide Label Automatically After Some Seconds Using JavaScript

In this tutorial we will explain how to Hide Label Automatically After Some Seconds Using JavaScript.Here we are using Textbox, Label and a submit button.By default label is set invisible, on click of button label is visible and will be invisible after 4 seconds automatically.

Design View:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Index.aspx.cs" Inherits="Hide_Label_Automatically_After_Some_Seconds.Index" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Hide Label Automatically After Some Seconds Using JavaScript</title>

<script type="text/javascript">
window.onload = function () {
var seconds = 4;
setTimeout(function () {
document.getElementById("<%=Autohide.ClientID %>").style.display = "none";
}, seconds * 1000);
};
</script>

<style type="text/css">
body
{
margin: 0px auto;
width:900px;
font-family:Calibri;
font-size:14px;
padding-top:100px;
text-align:center;
}
.lbl
{
font-family:Calibri;
font-size:24px;
color:#154004
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
<h2>Hide Label Automatically After Some Seconds Using JavaScript</h2>
    
<br /><br />
<asp:TextBox ID="Name" runat="server"></asp:TextBox>
<br />
<asp:Label ID="Autohide" runat="server" Visible="false" Text="Data has been Submitted" CssClass="lbl"></asp:Label><br /><br />
<asp:Button ID="Submit" runat="server" Text="Submit" OnClick="Submit_Click" />    
</div>
</form>
</body>
</html>

Code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Hide_Label_Automatically_After_Some_Seconds
{
public partial class Index : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Submit_Click(object sender, EventArgs e)
{
Autohide.Visible = true;
}
}
}

One reply on “Hide Label Automatically After Some Seconds Using JavaScript”

Patterns begin to make sense as we focus that positive energy
and apply it within our own lives. It’s an ideal source
of current information to spark interesting and useful ideas on a consistent basis.

Comments are closed.