Initial Chamber
Step 1
Open Visual Studio 2010 and create an empty website, name it Calendar_demo.
Step 2
In Solution Explorer you get your empty website, then add a Web Form as in the following.
For Web Form:
Calendar_demo (Your Empty Website) and right-click to Add New Item as Web Form, name it calendar_demo.aspx.
Design Chamber
Step 3
Now open your calendar_demo.aspx file and make some design code to build up your application like the following.
Calendar_demo.aspx
- <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %><%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>
- <!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>
- <style type="text/css">
- .style2
- {
- width: 95px;
- }
- .style3
- {
- width: 188px;
- }
- .style4
- {
- width: 23px;
- }
- .style5
- {
- text-decoration: underline;
- font-size: large;
- }
- .style6
- {
- width: 226px;
- }
- .style7
- {
- text-decoration: underline;
- font-size: x-large;
- }
- .style8
- {
- width: 258px;
- }
- .style9
- {
- width: 40px;
- }
- </style>
- </head>
- <body>
- <form id="form1" runat="server">
- <asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server"></asp:ToolkitScriptManager>
- <div id="man">
- <table style="width: 66%; margin-left: 119px;">
- <caption class="style5"></caption>
- <tr>
- <td class="style4">
- </td>
- <td class="style9">
- </td>
- <td class="style3">
- <asp:Label ID="Label2" runat="server" ForeColor="#6600FF"
- style="font-weight: 700; text-decoration: underline"
- Text="Student Admission Form"></asp:Label>
- </td>
- </tr>
- <tr>
- <td class="style4">
- </td>
- <td class="style9">
- </td>
- <td class="style3">
- </td>
- </tr>
- <tr>
- <td class="style4">
- </td>
- <td class="style9">
- </td>
- <td class="style3">
- </td>
- </tr>
- <tr>
- <td class="style4">
- </td>
- <td class="style9">
- Student Name</td>
- <td class="style3">
- <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
- <asp:BalloonPopupExtender ID="BalloonPopupExtender1" BalloonPopupControlID="Panel1" TargetControlID="TextBox1" runat="server"></asp:BalloonPopupExtender>
- <asp:Panel ID="Panel1" runat="server">
- Please Enter your Name
- </asp:Panel>
- </td>
- <td>
- </td>
- </tr>
- <tr>
- <td class="style4">
- </td>
- <td class="style9">
- Father Name</td>
- <td class="style3">
- <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
- <asp:BalloonPopupExtender ID="BalloonPopupExtender2" BalloonPopupControlID="Panel2" TargetControlID="TextBox2" runat="server"></asp:BalloonPopupExtender>
- <asp:Panel ID="Panel2" runat="server">
- Please Enter your Father Name
- </asp:Panel>
- </td>
- </tr>
- <tr>
- <td class="style4">
- </td>
- <td class="style9">
- Mother Name</td>
- <td class="style3">
- <asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>
- <asp:BalloonPopupExtender ID="BalloonPopupExtender3" BalloonPopupControlID="Panel3" TargetControlID="TextBox3" runat="server"></asp:BalloonPopupExtender>
- <asp:Panel ID="Panel3" runat="server">
- Please Enter your Mother Name
- </asp:Panel>
- </td>
- <td>
- </td>
- </tr>
- <tr>
- <td class="style4">
- </td>
- <td class="style9">
- Student Age
- </td>
- <td class="style3">
- <asp:TextBox ID="TextBox4" runat="server"></asp:TextBox>
- <asp:BalloonPopupExtender ID="BalloonPopupExtender5" BalloonPopupControlID="Panel5" TargetControlID="TextBox4" runat="server"></asp:BalloonPopupExtender>
- <asp:Panel ID="Panel5" runat="server">
- How old are you?
- </asp:Panel>
- </td>
- </tr>
- <tr>
- <td class="style2">
- </td>
- <td class="style9">
- <asp:CalendarExtender ID="CalendarExtender1" OnClientDateSelectionChanged="SelectDate" TargetControlID="TextBox4" runat="server"></asp:CalendarExtender>
- <script type="text/javascript">
- function SelectDate(e) {
- var PresentDay = new Date();
- var dateOfBirth = e.get_selectedDate();
- var months = (PresentDay.getMonth() - dateOfBirth.getMonth() + (12 * (PresentDay.getFullYear() - dateOfBirth.getFullYear())));
- alert("You Are Of " + Math.round(months / 12) + " Years");
- document.getElementById("TextBox6").value = Math.round(months / 12);
- }
- </script>
- </td>
- <td class="style3">
- <asp:TextBox ID="TextBox6" ReadOnly="true" runat="server" Font-Size="12px" ></asp:TextBox>
- </td>
- </tr>
- <tr>
- <td class="style4">
- </td>
- <td class="style9">
- Qualification</td>
- <td class="style3">
- <asp:DropDownList ID="DropDownList1" runat="server">
- <asp:ListItem>-- Select Class--</asp:ListItem>
- <asp:ListItem>1st</asp:ListItem>
- <asp:ListItem>2nd</asp:ListItem>
- <asp:ListItem>3rd</asp:ListItem>
- <asp:ListItem>4th</asp:ListItem>
- <asp:ListItem>5th</asp:ListItem>
- <asp:ListItem>6th</asp:ListItem>
- <asp:ListItem>7th</asp:ListItem>
- <asp:ListItem>8th</asp:ListItem>
- <asp:ListItem>9th</asp:ListItem>
- <asp:ListItem>10th</asp:ListItem>
- <asp:ListItem>11th</asp:ListItem>
- <asp:ListItem>12th</asp:ListItem>
- </asp:DropDownList>
- </td>
- </tr>
- <tr>
- <td class="style4">
- </td>
- <td class="style9">
- Phone No
- </td>
- <td class="style3">
- <asp:TextBox ID="TextBox5" runat="server"></asp:TextBox>
- <asp:BalloonPopupExtender ID="BalloonPopupExtender4" BalloonPopupControlID="Panel4" TargetControlID="TextBox5" runat="server"></asp:BalloonPopupExtender>
- <asp:Panel ID="Panel4" runat="server">
- Please Enter your PhoneNo
- </asp:Panel>
- </td>
- </tr>
- <tr>
- <td class="style4">
- </td>
- <td class="style9">
- </td>
- <td class="style3">
- </td>
- </tr>
- <tr>
- <td class="style4">
- </td>
- <td class="style9">
- </td>
- <td class="style3">
- <asp:Button ID="Button1" runat="server" Text="Submit" onclick="Button1_Click" />
- </td>
- </tr>
- </table>
- </div>
- <p>
- <table style="width:100%;">
- <caption class="style7"></caption>
- <tr>
- <td class="style6">
- </td>
- <td align="center" class="style8">
- </td>
- <td>
- </td>
- </tr>
- <tr>
- <td class="style6">
- </td>
- <td class="style8">
- </td>
- <td>
- </td>
- </tr>
- <tr>
- <td class="style6">
- </td>
- <td class="style8">
- <asp:Label ID="Label1" runat="server"></asp:Label>
- </td>
- </tr>
- </table>
- </p>
- </form>
- </body>
- </html>
Your design will look like the following.
Code Chamber
Step 4
Open your calendar_demo.aspx.cs file, where we will write the following code for printing the data that you provided in the TextBox in label.
Calendar_demo.aspx.cs
- 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)
- {
- }
- protected void Button1_Click(object sender, EventArgs e)
- {
- Label1.Text = "My Name is:" + TextBox1.Text + "</br>" + "My Father Name is:" + TextBox2.Text + "</br>" + "My Mothe Name is:" + TextBox3.Text + "</br>" + TextBox4.Text + "My DOB is:" + DropDownList1.SelectedItem.Text + "</br>" + "My Phone No is:" + TextBox5.Text + "</br>";
- Label1.ForeColor = System.Drawing.Color.Green;
- }
- }


Here it will automatically get your age by giving your date of birth.


I hope you like this. Have a nice day, Thank you for reading!

Arul RPosted Oct 28, 2015, 5:44 AM
Nice share!!!
Santhakumar MunuswamyPosted Jun 15, 2015, 2:27 PM
Thanks for nice article
NitinPosted Jun 15, 2015, 10:25 AM
good one
Former memberPosted Jun 15, 2015, 8:19 AM
Nice start, keep it up