Aspdotnet-Suresh

aspdotnet-suresh offers C#.net articles and tutorials,csharp dot net,asp.net articles and tutorials,VB.NET Articles,Gridview articles,code examples of asp.net 2.0 /3.5,AJAX,SQL Server Articles,examples of .net technologies

how to display Good Morning,Good Afternoon and Good Evening Messages based on time in asp.net

Oct 22, 2010
Introduction

I will explain how to display Good Morning,Good Afternoon and Good Evening Messages based on time in asp.net

Description

In some of websites we will see greeting messages like good morning, good afternoon and good evening messages how to display those messages in our website. Basically those messages will display by calculating present time and we can display that greeting messages.

For that first design your aspx page like this  


<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Time Based Greeting Message in asp.net</title>
</head>
<body onload="">
<form id="form1" runat="server">
<div>
<asp:Label ID="lblGreeting" runat="server" />
<asp:Label ID="lblDate" runat="server"/>
</div>
</form>
</body>
</html>
After that write the following code in code behind


protected void Page_Load(object sender, EventArgs e)
{
if(DateTime.Now.Hour<12)
{
lblGreeting.Text = "Good Morning";
lblDate.Text = Convert.ToString(DateTime.Now);
}
else if(DateTime.Now.Hour<17)
{
lblGreeting.Text = "Good Afternoon";
lblDate.Text = Convert.ToString(DateTime.Now);
}
else
{
lblGreeting.Text = "Good Evening";
lblDate.Text = Convert.ToString(DateTime.Now);
}
}

If you enjoyed this post, please support the blog below. It's FREE!

Get the latest Asp.net, C#.net, VB.NET, jQuery, Plugins & Code Snippets for FREE by subscribing to our Facebook, Twitter, RSS feed, or by email.

subscribe by rss Subscribe by RSS subscribe by email Subscribe by Email
© 2015 Aspdotnet-Suresh.com. All Rights Reserved.
The content is copyrighted to Suresh Dasari and may not be reproduced on other websites without permission from the owner.