Age Calculator using ASP.NET & C#

3 Comments | 1924 Views | Post by: Admin | Tags: Age Calculator using ASP.NET & C#


Age Calculator using ASP.NET & C#


Introduction

Here Pawan Kumar will explain how to Age Calculator using ASP.NET & C#

Description

In previous post I have explained How to Create Tab Control Using jQuery In Asp.Net, jQuery Datepicker Calendar With Slide Down Effect In Asp.Net, jQuery Code To Select Multiple Item By Pressing Ctrl Button In Asp.Net, How to bind dropdown list with XML file in asp.net?, Validate ASP.Net form using CSS in C#, API Demonstration ASP.NET, and many more articles.

Now I will explain How to Age Calculator using ASP.NET & C#

So follow the steps to learn Age Calculator using ASP.NET & C#

ASPX Code:-

<%@ 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>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <h1>
            Age Calculator using ASP.NET & C#</h1>
    </div>
    <p>
        <asp:Label ID="lblAge" runat="server" Font-Bold="True" Font-Size="Larger"></asp:Label>
    </p>
    </form>
</body>
</html>

Code Behind:-

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 Page_Load(object sender, EventArgs e)
    {
        DateTime birthday = new DateTime(1981, 06, 15);

        DateTime today = DateTime.Today;
        int age = today.Year - birthday.Year;
        if (birthday > today.AddYears(-age))
            lblAge.Text = age.ToString(); ;
    }
}

Output Screenshot:-

Conclusion:

So, In this tutorial we have learned, Age Calculator using ASP.NET & C#

Download Source Codes


Post Comments

if you have some suggestion, question, request on Age Calculator using ASP.NET & C#.

Please use the comment box to express your views.

 

Comments:

loading...