JavaScript Editor JavaScript Editor     JavaScript Debugger

Previous Section Next Section

Main Page

Creating Calendars

You can see a calendar control in the Calendars example on the CD-ROM, which is also shown in Figure 18.3. By clicking the arrow buttons at top left and right in the calendar control, you can select a month, and by double-clicking the control, you can select a day, causing a SelectionChanged event. To determine the selected date, you can use the SelectedDate property, as I do in the Calendars example:

    Private Sub Calendar1_SelectionChanged(ByVal sender As _
        System.Object, ByVal e As System.EventArgs) Handles _
        Calendar1.SelectionChanged
        TextBox1.Text = "You selected " & Calendar1.SelectedDate
    End Sub

To find more details on the properties and events of calendar Web server controls, see the In Depth section of this chapter. Here's the code for WebForm1.aspx for the Calendars example:

<%@ Page Language="vb" AutoEventWireup="false"
Codebehind="WebForm1.aspx.vb" Inherits="Calendars.WebForm1"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
  <HEAD>
    <title>Calendars example</title>
    <meta name="GENERATOR" content="Microsoft Visual Studio.NET 7.0">
    <meta name="CODE_LANGUAGE" content="Visual Basic 7.0">
    <meta name=vs_defaultClientScript content="JavaScript">
    <meta name=vs_targetSchema
        content="http://schemas.microsoft.com/intellisense/ie5">
  </HEAD>
  <body MS_POSITIONING="GridLayout">

    <form id="Form1" method="post" runat="server">
<asp:Calendar id=Calendar1 style="Z-INDEX: 101; LEFT: 114px;
POSITION: absolute; TOP: 43px" runat="server"></asp:Calendar>
<asp:TextBox id=TextBox1 style="Z-INDEX: 102; LEFT: 160px;
POSITION: absolute; TOP: 245px" runat="server"></asp:TextBox>
    </form>
  </body>
</HTML>

And here's the code for the WebForm1.aspx.vb file in this example:

Public Class WebForm1
    Inherits System.Web.UI.Page
    Protected WithEvents TextBox1 As System.Web.UI.WebControls.TextBox
    Protected WithEvents Calendar1 As _
        System.Web.UI.WebControls.Calendar

#Region " Web Form Designer Generated Code "

    'This call is required by the Web Form Designer.
    <System.Diagnostics.DebuggerStepThrough()> _
        Private Sub InitializeComponent()

    End Sub

    Private Sub Page_Init(ByVal sender As System.Object, _
        ByVal e As System.EventArgs) Handles MyBase.Init
        'CODEGEN: This method call is required by the Web Form Designer
        'Do not modify it using the code editor.
        InitializeComponent()
    End Sub

#End Region

    Private Sub Page_Load(ByVal sender As System.Object, _
        ByVal e As System.EventArgs) Handles MyBase.Load
        'Put user code to initialize the page here
    End Sub

    Private Sub Calendar1_SelectionChanged(ByVal sender As _
        System.Object, ByVal e As System.EventArgs) Handles _
        Calendar1.SelectionChanged
        TextBox1.Text = "You selected " & Calendar1.SelectedDate
    End Sub
End Class
Previous Section Next Section




JavaScript Editor Free JavaScript Editor     JavaScript Editor