Q&A
Can I use HTML controls instead of Web controls for the textboxes in the HTML portion of the ASP.NET Web page?
Yes, but I would advise against it, in large part because the Web Matrix Project's Toolbox does not contain support for dragging and dropping HTML controls. Rather, you would have to enter the markup for the HTML controls by hand in the HTML tab. That is, there are no HTML controls in the Web Matrix Project's Toolbox, just Web controls and HTML elements.
Additionally, we will be using Web controls extensively throughout this book, so I would encourage you to familiarize yourself with adding Web controls to an ASP.NET Web page and consider using HTML controls only when an example explicitly mentions their use.
How do I associate "event code" with a Web control that I've placed on a Web Form?
In this hour we saw how to have the Button Web control's Click event associated with an event handler provided in the source code section. We accomplished this by simply double-clicking the Button Web control in the designer. Realize that, behind the scenes, the Web Matrix Project is performing a number of steps when you double-click the Button. Each Web control has a default event. When the Web control is double-clicked in the designer, an event handler is created for this default event. (Note that the Button Web control's default event is the Click event.)
Adding an event handler for an event other than a Web control's default event involves a more thorough discussion than we are ready for at this point. We'll examine adding event handlers for events other than the Web control's default event in the next hour.
What would happen if I placed the financial calculation code in the Page_Load event instead of the button Click event handler?
Recall that the source code in the Page_Load event handler executes every time the ASP.NET Web page is requested. When the page is visited for the first time by the user, the user has yet to enter the loan principal, interest rate, and duration. Therefore, in attempting to compute the calculation, we will get an error.
Because we want to perform the calculation only after the user has provided the required inputs, the source code for the calculation is placed in the button's Click event handler.