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. |
|||
|
|||
7 comments :
cute program
Simple one
nice post..
Good one and simple
Thanks
Thanks
thanks for saving my time
output plz
Note: Only a member of this blog may post a comment.