Select the Design tab again. Double-click the Calendar control to automatically associate an ASP.NET server-side event-handler method with the control's SelectionChanged event and open the page in Code view. The event handler is named Calendar1_SelectionChanged. Add code in the event handler so that the subroutine looks like the following:
Sub Calendar1_SelectionChanged _
(ByVal sender As Object, _
ByVal e As EventArgs)
Label1.Text = "You have" & _ "
selected: " & _
Calendar1.SelectedDate()
End Sub
A user who opens this page in a browser can click a date on the calendar to select it. ASP.NET calls the same page again with different parameters and displays the message "You have selected: day/month/year," where day/month/year is the day, month, and year the user selected. Click the Save icon on the toolbar to save the page. Then you can run the page.
Running the ASP.NET Page
The ASP.NET Web Matrix installation program installs a Web server that runs side by side with IIS if IIS is installed on your computer. Both Web servers run ASP.NET Web Matrixbuilt pages exactly the same way because the Web servers use the same ASP.NET runtime engine built on the .NET Framework.
To run the page you just created, select Start from the ASP.NET Web Matrix IDE's View menu, click the Start icon on the Standard Toolbar, or press the F5 key. You'll see the Start Web Application dialog box, which Figure 3 shows. To run the page in the ASP.NET Web Matrix Web server, make sure the default Use ASP.NET Web Matrix Server option is selected and click Start. The ASP.NET Web Matrix Server will start, and the page will run in a browser. Click a date on the calendar to see your ASP.NET Web application in action, as Figure 4 shows.
Notice that your computer's taskbar shows that the ASP.NET Web Matrix Server is running. ASP.NET Web Matrix doesn't ask you how to run subsequent pages after you've chosen ASP.NET Web Matrix Server and it's running. To run your page in IIS, you first need to stop the ASP.NET Web Matrix Server. Right-click the ASP.NET Web Matrix Server taskbar icon and select Stop. Return to the ASP.NET Web Matrix IDE and press F5. At the Start Web Application dialog box, select the Use or create an IIS Virtual Root option. In the Application Name field, enter a logical name for a virtual directory (e.g., WebMatrix). When you click Start, IIS creates a virtual directory and runs the page.
If you want to run the page under the ASP.NET Web Matrix Server again, you must exit ASP.NET Web Matrix. Then you must restart the program, load the page, and run the application.
Prototyping Tool
A software-development revolution is happeningnetwork and infrastructure folks and program, product, and project managers are using tools such as ASP.NET Web Matrix to build prototype and pilot applications that they then "throw over the wall" to developers. What a perfect story for building enterprise applicationsactually enabling users to help scope projects through prototyping and piloting.
ASP.NET Web Matrix was built for single-developer Web application development. Unlike Visual Studio .NET, ASP.NET Web Matrix doesn't provide support for team-based development and doesn't support features such as IntelliSense (syntactical completion of words while typing) and debugging. The tool does provide a way to quickly start building ASP.NET applications that you can subsequently upgrade to Visual Studio .NET. Microsoft has promised to provide an upgrade wizard in future ASP.NET Web Matrix versions.
In a future article, I'll step you through more of ASP.NET Web Matrix's features. I'll also show you how to build an application that you can use as the basis of many data-driven Web applications.