Hello everyone!! In this article I am going to make a simple application based on ASP.NET Web Forms which includes a few server controls such as Calendar control.

To get started,

Follow these steps

Step 1 -

Open your latest version of Visual Studio. Select File,
New, then Project to see the following screen.Under the section of Visual C#, click on ASP.NET Empty Web Application. Name it EventApp.

Step 2 -

Click on OK Button to load the project .On the left hand side of the Solution Explorer right click on your project name and add a new Web Form. Name it Event.aspx as follows.

Click on Add button to load the main project.

Step 3 - Add the following code to the Event.aspx page,

  1. <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Event.aspx.cs" Inherits="EventApp.Event" %>
  2. <!DOCTYPE html>
  3. <html xmlns="http://www.w3.org/1999/xhtml">
  4. <head runat="server">
  5. <title></title>
  6. </head>
  7. <body>
  8. <form id="form1" runat="server">
  9. <div>
  10. <h1 style="text-align: center;">
  11. Enter details and set a day to initiate an event.
  12. </h1> </div>
  13. <div style="text-align: center;">
  14. <table style="text-align: left; margin:auto; border-color: #000000;
  15. border-width: 2px; background-color: #fff99e;" cellspacing="0" cellpadding="8" rules="none" width="540">
  16. <tr>
  17. <td valign="top">Your Name:</td>
  18. <td valign="top">
  19. <asp:TextBox ID="nameBox" Runat="server" Width="160px" />
  20. <asp:RequiredFieldValidator ID="validateName"
    Runat=
    "server" ErrorMessage="You must enter a name."
    ControlToValidate="nameBox" Display="None" /> </td>
  21. <td valign="middle" rowspan="4">
  22. <asp:Calendar ID="calendar" Runat="server" BackColor="White" /> </td>
  23. </tr>
  24. <tr>
  25. <td valign="top"> Event Name:</td>
  26. <td valign="top">
  27. <asp:TextBox ID="eventBox" Runat="server" Width="160px" />
  28. <asp:RequiredFieldValidator ID="validateEvent" Runat="server"
    ErrorMessage=
    "You must enter an event name." ControlToValidate="eventBox" Display="None" /> </td>
  29. </tr>
  30. <tr>
  31. <td valign="top"> Meeting Room:</td>
  32. <td valign="top">
  33. <asp:DropDownList ID="roomList" Runat="server" Width="160px">
  34. <asp:ListItem Value="1">The Happy Room</asp:ListItem>
  35. <asp:ListItem Value="2">The Angry Room</asp:ListItem>
  36. <asp:ListItem Value="3">The Depressing Room</asp:ListItem>
  37. <asp:ListItem Value="4">The Funked Out Room</asp:ListItem>
  38. </asp:DropDownList>
  39. <asp:RequiredFieldValidator ID="validateRoom" Runat="server"
    ErrorMessage=
    "You must select a room." ControlToValidate="roomList" Display="None" /> </td>
  40. </tr>
  41. <tr>
  42. <td valign="top"> Attendees:</td>
  43. <td valign="top">
  44. <asp:ListBox ID="attendeeList" Runat="server" Width="160px" SelectionMode="Multiple" Rows="6">
  45. <asp:ListItem Value="1">Bill Gates</asp:ListItem>
  46. <asp:ListItem Value="2">Steve Jobs</asp:ListItem>
  47. <asp:ListItem Value="3">Mark Zuckerberg</asp:ListItem>
  48. <asp:ListItem Value="4">William Hewlett</asp:ListItem>
  49. <asp:ListItem Value="5">Bob Packard</asp:ListItem>
  50. <asp:ListItem Value="6">Larry Page</asp:ListItem>
  51. </asp:ListBox>
  52. <asp:RequiredFieldValidator ID="validateAttendees" Runat="server"
    ErrorMessage=
    "You must have at least one attendee." ControlToValidate="attendeeList" Display="None" /> </td>
  53. </tr>
  54. <tr>
  55. <td align="center" colspan="3">
  56. <asp:Button ID="submitButton" Runat="server" Width="100%"
    Text=
    "Submit meeting room request" onclick="submitButton_Click" /> </td>
  57. </tr>
  58. <tr>
  59. <td align="center" colspan="3">
  60. <asp:ValidationSummary ID="validationSummary" Runat="server"
    HeaderText=
    "Before submitting your request:" /> </td>
  61. </tr>
  62. </table>
  63. </div>
  64. <table>
  65. <tr>
  66. <td height="50"></td>
  67. </tr>
  68. </table>
  69. <table style="text-align: left; margin:auto; border-color: #000000;
  70. border-width: 2px; background-color:lightgoldenrodyellow;" cellspacing="0" cellpadding="8" rules="none" width="540">
  71. <tr>
  72. <td>
  73. <p style="text-align:center;"> Results:
  74. <asp:Label Runat="server" ID="resultLabel" Text="None." /> </p>
  75. </td>
  76. </tr>
  77. </table>
  78. </form>
  79. </body>
  80. </html>
Step 4 - Open the Event.aspx.cs page and the following code to it,

  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. if (!this.IsPostBack)
  12. {
  13. calendar.SelectedDate = DateTime.Now;
  14. }
  15. }
  16. protected void submitButton_Click(object sender, EventArgs e)
  17. {
  18. if (this.IsValid)
  19. {
  20. resultLabel.Text = roomList.SelectedItem.Text + " has been booked on " +
    calendar.SelectedDate.ToLongDateString() +
    " by " + nameBox.Text + " for " + eventBox.Text + " event. ";
  21. foreach(ListItem attendee in attendeeList.Items)
  22. {
  23. if (attendee.Selected)
  24. {
  25. resultLabel.Text += attendee.Text + ", ";
  26. }
  27. }
  28. resultLabel.Text += " and " + nameBox.Text + " will be attending.";
  29. }
  30. }
  31. }
Step 5 - Save the project and build it to see the following output,