title: Calendar Controls, Event Handler for Load Event
body: <p>I have been working on this for quite a while now. My code will show all the different ways and things that I have tried to get the problem fixed, but with no luck...so far. What I need to do is:</p>
  
  <ol>
  <li>Start an event handler for the Load event of the form. Then add code to display the current date in the format shown above if the form is not being posted back.</li>
  <li>Add a calendar control to the next paragraph, and set its Visible property to False so it's hidden when the form is first displayed.</li>
  <li>Code an event handler for the Click event of the image button. This shold hide the image button and display the calendar control.</li>
  <li>Code an event handler for the SelectionChanged event of the calendar control. This should get the selected date and display it in the text box with today's date and should also hide the calendar control and display the image button.</li>
  </ol>
  
  <p>I hope that someone can help me sort out what I am doing wrong and help me get to the correct solution. Not really happy with the outcome so far.</p>
  
  <p>My code-behind:</p>
  
  <pre><code>Partial Class Request
      Inherits Page
  
  Dim ImageButton1 As ImageButton1
  
  Protected Sub Calendar_SelectionChanged(object sender, EventArgs e)
      Label.Text = "Current date: " + System.DateTime.Now.ToLongDateString()
      Label.Text = "Selected date: " + Calendar.SelectedDate.ToLongDateString()
  
      Dim label1 = System.DateTime.Now
      Dim label2 = SelectedDate
      Dim ImageButton1 = ImageButton1
  End Sub
  
  protected void Calendar_SelectionChanged(object sender, EventArgs e)
  {
      lblday.Text = Calendar1.TodaysDate.ToShortDateString();
      lblbday.Text = Calendar1.SelectedDate.ToShortDateString();
  }
  
  ' Display using current (en-us) culture's short date format 
  Dim ddlDate As Date = #3/15/2008#
  
  Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles   Me.Load
     Calendar.SelectedDate = DateTime.Now;
     Label.Text = "Today's date and time is :" + Calendar.SelectedDate;
     Calendar.SelectedDate = DateTime.Today
  End Sub
  
  Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
      If Not IsPostBack Then
          Me.clnArrival = thisDate.ToString
      End If
  End Sub
  
  Sub Submit(s As Object, e As EventArgs)
      TextBox1.Text = "The date and time is " &amp; Now()
  End Sub
  
  Protected Sub ddlDay_SelectedIndexChanged(ByVal sender As Object, ByVal e As   EventArgs) Handles ddlDay.SelectedIndexChanged
      clnArrival.Visible = False
      Dim day As String = ddlDay.SelectedItem.Text(ddlDay.SelectedValue)
  End Sub
  
  Protected Sub ddlMonth_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs) Handles ddlMonth.SelectedIndexChanged
      Dim month As String = ddlMonth.SelectedItem.Text(ddlMonth.SelectedValue)
  End Sub
  
   Protected Sub clnArrival_SelectionChanged(ByVal sender As Object, ByVal e As EventArgs) Handles clnArrival.SelectionChanged
      ddlMonth_SelectedValue = clnArrival.SelectedDate.Month.ToString
      ddlDay_SelectedValue = clnArrival.SelectedDate.Day.ToString
      clnArrival.Visible = True
  End Sub
  End Class
  </code></pre>
  
  <p>My markup:</p>
  
  <pre><code>&lt;%@ Page Language="VB" AutoEventWireup="false" CodeFile="Request.aspx.vb" Inherits="Request" %&gt;
  
  &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
  
  &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
  &lt;head runat="server"&gt;
      &lt;title&gt;Chapter 6: Reservations&lt;/title&gt;
      &lt;link href="Styles/Main.css" rel="stylesheet" type="text/css" /&gt;
      &lt;link href="Styles/Request.css" rel="stylesheet" type="text/css" /&gt;
  
      &lt;script language="VB" runat="server"&gt;
          Sub Page_Load()
              Response.Write("Today is: ")
          End Sub
      &lt;/script&gt;    
  &lt;/head&gt;
  &lt;body&gt;
  &lt;form id="form1" runat="server"&gt;
      &lt;div id="page"&gt;
          &lt;h1&gt;Royal Inn and Suites&lt;/h1&gt;
          &lt;h2&gt;Where you&amp;rsquo;re always treated like royalty&lt;/h2&gt;
          &lt;p id="arrival_date"&gt;
              Arrival date:&amp;nbsp;
  
          &lt;asp:Calendar ID = "Calendar" runat = "server" SelectionMode="DayWeekMonth" OnSelectionChanged="Calendar_SelectionChanged" SelectedDate="1/1/0001" VisibleDate="1/1/0001"&gt;
              &lt;asp:ImageButton ID="ImageButton1" runat="server" AlternateText="Click to show calendar" ImageUrl="C:\aspnet4_vb\Jeanne Tatro Webs 424 - HW 6 - Ch06Reservation\Images\Calendar.bmp" /&gt;
          &lt;/asp:Calendar&gt;
          &lt;/p&gt;
          &lt;p class="clear"&gt;
              Number of nights:&amp;nbsp; 
          &lt;/p&gt;
          &lt;p&gt;
              Number of adults:&amp;nbsp;
              Children:&amp;nbsp;
          &lt;/p&gt;
          &lt;h3&gt;Preferences&lt;/h3&gt;
          &lt;p&gt;
              Room type:&amp;nbsp;
          &lt;/p&gt;
          &lt;p&gt;
              Bed type:&amp;nbsp;
          &lt;/p&gt;
          &lt;p id="requests"&gt;Special requests:&lt;/p&gt;
          &lt;h3 class="clear"&gt;Contact information&lt;/h3&gt;
          &lt;p class="contact"&gt;Name:&lt;/p&gt;
          &lt;p class="contact"&gt;Email:&lt;/p&gt;
          &lt;p id="buttons"&gt;&lt;/p&gt;
          &lt;p id="message"&gt;&lt;/p&gt;
      &lt;/div&gt;
  &lt;/form&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>