Saturday, 12 October 2013

AUTOMATICALLY HIDE LABEL AFTER SOME SECONDS (5 SECONDS) IN ASP.NET

Designer Page:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs"
 Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <style type="text/css">
        body
        {
            font-family: Arial;
            font-size: 10pt;
        }
    </style>
</head>
<body>
    <form id="form1" runat="server">
    Enter Name:
    <asp:TextBox ID="txtName" runat="server" />
    <br />
    <asp:Button Text="Submit" runat="server" OnClick="Submit" /><br />
    <br />
    <asp:Label ID="lblMessage" ForeColor="Green" Font-Bold="true" Text="Form 
          has been submitted successfully."
        runat="server" Visible="false" />
    <script type="text/javascript">
        window.onload = function () {
            var seconds = 5;
            setTimeout(function () {
                document.getElementById("<%=lblMessage.ClientID %>").
                 style.display = "none";
            }, seconds * 1000);
        };
    </script>
    </form>
</body>
</html>

C# Code :

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

public partial class _Default : System.Web.UI.Page
{
    protected void Submit(object sender, EventArgs e)
    {
        lblMessage.Visible = true;
    }
}

No comments:

Post a Comment