Menu

Calculate age using ajax calender

Hi Friend,

Here, i have provide simple demo for calculate age from ajax calender.

Download Source Code => CalculateAgeFromAjaxCalender.rar

Step 1. Aspx Code 


<table>
 <tr>
 <td>
 BOD:
 </td>
 <td>
 <asp:TextBox ID="txtBOD" runat="server" />
 <ajax:CalendarExtender ID="ceCalender" runat="server" TargetControlID="txtBOD" Format="MMMM dd, yyyy" />
 </td>
 </tr>
 <tr>
 <td>
 <asp:Button ID="btnAgeCalculate" runat="server" Text="AgeCalculate" OnClick="btnAgeCalculate_Click" />
 </td>
 <td>
 </td>
 </tr>
 <tr>
 <td>
 Total Age:
 </td>
 <td>
 <asp:Label ID="lblTotalAge" runat="server" />
 </td>
 </tr>
 </table>

Step 1. Aspx.Cs Code


protected void btnAgeCalculate_Click(object sender, EventArgs e)
 {
 int currentDate = int.Parse(DateTime.Today.ToString("yyyyMMdd"));

int bod = int.Parse(Convert.ToDateTime(txtBOD.Text).ToString("yyyyMMdd"));

string dif = (currentDate - bod).ToString();

string age = "0";

if (dif.Length > 4)
 age = dif.Substring(0, dif.Length - 4);
 lblTotalAge.Text = age;
 }

No comments

Leave a Reply


− 1 = 8

Categories