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:

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

  1. <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %><%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>
  2. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  3. <html
  4. xmlns="http://www.w3.org/1999/xhtml">
  5. <head runat="server">
  6. <title></title>
  7. <style type="text/css">
  8. .style2
  9. {
  10. width: 95px;
  11. }
  12. .style3
  13. {
  14. width: 188px;
  15. }
  16. .style4
  17. {
  18. width: 23px;
  19. }
  20. .style5
  21. {
  22. text-decoration: underline;
  23. font-size: large;
  24. }
  25. .style6
  26. {
  27. width: 226px;
  28. }
  29. .style7
  30. {
  31. text-decoration: underline;
  32. font-size: x-large;
  33. }
  34. .style8
  35. {
  36. width: 258px;
  37. }
  38. .style9
  39. {
  40. width: 40px;
  41. }
  42. </style>
  43. </head>
  44. <body>
  45. <form id="form1" runat="server">
  46. <asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server"></asp:ToolkitScriptManager>
  47. <div id="man">
  48. <table style="width: 66%; margin-left: 119px;">
  49. <caption class="style5"></caption>
  50. <tr>
  51. <td class="style4">
  52. </td>
  53. <td class="style9">
  54. </td>
  55. <td class="style3">
  56. <asp:Label ID="Label2" runat="server" ForeColor="#6600FF"
  57. style="font-weight: 700; text-decoration: underline"
  58. Text="Student Admission Form"></asp:Label>
  59. </td>
  60. </tr>
  61. <tr>
  62. <td class="style4">
  63. </td>
  64. <td class="style9">
  65. </td>
  66. <td class="style3">
  67. </td>
  68. </tr>
  69. <tr>
  70. <td class="style4">
  71. </td>
  72. <td class="style9">
  73. </td>
  74. <td class="style3">
  75. </td>
  76. </tr>
  77. <tr>
  78. <td class="style4">
  79. </td>
  80. <td class="style9">
  81. Student Name</td>
  82. <td class="style3">
  83. <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
  84. <asp:BalloonPopupExtender ID="BalloonPopupExtender1" BalloonPopupControlID="Panel1" TargetControlID="TextBox1" runat="server"></asp:BalloonPopupExtender>
  85. <asp:Panel ID="Panel1" runat="server">
  86. Please Enter your Name
  87. </asp:Panel>
  88. </td>
  89. <td>
  90. </td>
  91. </tr>
  92. <tr>
  93. <td class="style4">
  94. </td>
  95. <td class="style9">
  96. Father Name</td>
  97. <td class="style3">
  98. <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
  99. <asp:BalloonPopupExtender ID="BalloonPopupExtender2" BalloonPopupControlID="Panel2" TargetControlID="TextBox2" runat="server"></asp:BalloonPopupExtender>
  100. <asp:Panel ID="Panel2" runat="server">
  101. Please Enter your Father Name
  102. </asp:Panel>
  103. </td>
  104. </tr>
  105. <tr>
  106. <td class="style4">
  107. </td>
  108. <td class="style9">
  109. Mother Name</td>
  110. <td class="style3">
  111. <asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>
  112. <asp:BalloonPopupExtender ID="BalloonPopupExtender3" BalloonPopupControlID="Panel3" TargetControlID="TextBox3" runat="server"></asp:BalloonPopupExtender>
  113. <asp:Panel ID="Panel3" runat="server">
  114. Please Enter your Mother Name
  115. </asp:Panel>
  116. </td>
  117. <td>
  118. </td>
  119. </tr>
  120. <tr>
  121. <td class="style4">
  122. </td>
  123. <td class="style9">
  124. Student Age
  125. </td>
  126. <td class="style3">
  127. <asp:TextBox ID="TextBox4" runat="server"></asp:TextBox>
  128. <asp:BalloonPopupExtender ID="BalloonPopupExtender5" BalloonPopupControlID="Panel5" TargetControlID="TextBox4" runat="server"></asp:BalloonPopupExtender>
  129. <asp:Panel ID="Panel5" runat="server">
  130. How old are you?
  131. </asp:Panel>
  132. </td>
  133. </tr>
  134. <tr>
  135. <td class="style2">
  136. </td>
  137. <td class="style9">
  138. <asp:CalendarExtender ID="CalendarExtender1" OnClientDateSelectionChanged="SelectDate" TargetControlID="TextBox4" runat="server"></asp:CalendarExtender>
  139. <script type="text/javascript">
  140. function SelectDate(e) {
  141. var PresentDay = new Date();
  142. var dateOfBirth = e.get_selectedDate();
  143. var months = (PresentDay.getMonth() - dateOfBirth.getMonth() + (12 * (PresentDay.getFullYear() - dateOfBirth.getFullYear())));
  144. alert("You Are Of " + Math.round(months / 12) + " Years");
  145. document.getElementById("TextBox6").value = Math.round(months / 12);
  146. }
  147. </script>
  148. </td>
  149. <td class="style3">
  150. <asp:TextBox ID="TextBox6" ReadOnly="true" runat="server" Font-Size="12px" ></asp:TextBox>
  151. </td>
  152. </tr>
  153. <tr>
  154. <td class="style4">
  155. </td>
  156. <td class="style9">
  157. Qualification</td>
  158. <td class="style3">
  159. <asp:DropDownList ID="DropDownList1" runat="server">
  160. <asp:ListItem>-- Select Class--</asp:ListItem>
  161. <asp:ListItem>1st</asp:ListItem>
  162. <asp:ListItem>2nd</asp:ListItem>
  163. <asp:ListItem>3rd</asp:ListItem>
  164. <asp:ListItem>4th</asp:ListItem>
  165. <asp:ListItem>5th</asp:ListItem>
  166. <asp:ListItem>6th</asp:ListItem>
  167. <asp:ListItem>7th</asp:ListItem>
  168. <asp:ListItem>8th</asp:ListItem>
  169. <asp:ListItem>9th</asp:ListItem>
  170. <asp:ListItem>10th</asp:ListItem>
  171. <asp:ListItem>11th</asp:ListItem>
  172. <asp:ListItem>12th</asp:ListItem>
  173. </asp:DropDownList>
  174. </td>
  175. </tr>
  176. <tr>
  177. <td class="style4">
  178. </td>
  179. <td class="style9">
  180. Phone No
  181. </td>
  182. <td class="style3">
  183. <asp:TextBox ID="TextBox5" runat="server"></asp:TextBox>
  184. <asp:BalloonPopupExtender ID="BalloonPopupExtender4" BalloonPopupControlID="Panel4" TargetControlID="TextBox5" runat="server"></asp:BalloonPopupExtender>
  185. <asp:Panel ID="Panel4" runat="server">
  186. Please Enter your PhoneNo
  187. </asp:Panel>
  188. </td>
  189. </tr>
  190. <tr>
  191. <td class="style4">
  192. </td>
  193. <td class="style9">
  194. </td>
  195. <td class="style3">
  196. </td>
  197. </tr>
  198. <tr>
  199. <td class="style4">
  200. </td>
  201. <td class="style9">
  202. </td>
  203. <td class="style3">
  204. <asp:Button ID="Button1" runat="server" Text="Submit" onclick="Button1_Click" />
  205. </td>
  206. </tr>
  207. </table>
  208. </div>
  209. <p>
  210. <table style="width:100%;">
  211. <caption class="style7"></caption>
  212. <tr>
  213. <td class="style6">
  214. </td>
  215. <td align="center" class="style8">
  216. </td>
  217. <td>
  218. </td>
  219. </tr>
  220. <tr>
  221. <td class="style6">
  222. </td>
  223. <td class="style8">
  224. </td>
  225. <td>
  226. </td>
  227. </tr>
  228. <tr>
  229. <td class="style6">
  230. </td>
  231. <td class="style8">
  232. <asp:Label ID="Label1" runat="server"></asp:Label>
  233. </td>
  234. </tr>
  235. </table>
  236. </p>
  237. </form>
  238. </body>
  239. </html>

Your design will look like the following.

Design

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

  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 _Default : 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 = "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>";
  15. Label1.ForeColor = System.Drawing.Color.Green;
  16. }
  17. }
Output Chamber

Output

calendar control

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

date of birth

student admission form

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