Sunday, 13 April 2014

How to Display Date Time And Message in ASP.NET

Create a Web Site to display Message as shown in output to Handling Events and Post backs property Of Web page also display Current date & time in a label.


******HTML Code*****************************
  1. <html xmlns="http://www.w3.org/1999/xhtml">
  2. <head runat="server">
  3.     <title></title>
  4. </head>
  5. <body>
  6.     <form id="form1" runat="server">
  7.     <div style="Margin-left:38px; height: 206px;">
  8.      
  9.         <br />
  10.         Enter Your Name :
  11.         <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
  12.         <br />
  13.         <br />
  14. &nbsp;<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
  15.         <br />
  16.         <br />
  17. &nbsp;<asp:Label ID="Label2" runat="server" Text="Label"></asp:Label>
  18.         <br />
  19.         <br />
  20.         <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Show" />
  21.      
  22.     </div>
  23.     </form>
  24. </body>
  25. </html>

******C# Code*****************************
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5. using System.Web.UI;
  6. using System.Web.UI.WebControls;

  7. public partial class Display_Date_Time_And_Message : System.Web.UI.Page
  8. {
  9.     protected void Page_Load(object sender, EventArgs e)
  10.     {

  11.     }
  12.     protected void Button1_Click(object sender, EventArgs e)
  13.     {
  14.         Label1.Text = TextBox1.Text + " " + "Welcome To Facebook";
  15.         Label2.Text = DateTime.Now.ToString();
  16.     }
  17. }

No comments:

Post a Comment