Workshop
Quiz
Why is the design requirements phase of software development an important one?
How can one add a TextBox Web control to an ASP.NET Web page using the Web Matrix Project?
Why did we add a Label Web control to our ASP.NET Web page's HTML portion?
What will the ASP.NET Web page's output be if the user enters invalid characters into the textboxesfor example, if under the Mortgage Amount textbox, the user enters "Scott"?
How do you add an event handler for a Button Web control's Click event with the Web Matrix Project?
When using a TextBox Web control, what property is referenced to determine the value entered by the user?
Answers
-
The design requirements phase outlines the specific features for the software project and also outlines the user interface. It is an important stage because by enumerating the features, youand your boss and clientcan easily determine the current progress of the project. Furthermore, there is no ambiguity as to what features should and should not be included.
-
To add a TextBox Web control, simply click the TextBox Web control from the Toolbox and drag it onto the designer.
-
A Label Web control was added to the ASP.NET Web page's HTML portion to indicate where the output of the financial calculator would appear. Without using a label, we could output the results using only Response.Write() statements. Recall from the previous hour that this would have the effect of omitting the results before the HTML portion of the ASP.NET Web page. By using a Label Web control, then, we have more flexibility over where the output appears in the HTML portion.
-
If the user provides invalid input, a run-time error will occur.
-
To add an event handler for a Button Web control's Click event, simply double-click the button that you wish to add an event handler for.
-
The Text property contains the value entered by the user. To reference this property in an ASP.NET Web page's source code portion, we can use
TextBoxID.Text
Exercises
- In this hour we saw how to use the Web Matrix Project to create an
ASP.NET Web page with TextBox Web controls, a Button Web control, and a Label
Web control. Using this knowledge, let's create an ASP.NET Web page that
will prompt the user for his name and age. Once the user provides this
information and clicks the submit button, the ASP.NET Web page will display a
message whose content depends on the user's age.
This ASP.NET Web page will need to have two TextBox Web controls, a Button Web control, and a Label Web control. Set the TextBox Web controls' ID properties to name and age. The Button Web control should have its Text property set to Click Me. Set the Label Web control's ID property to results and clear out its Text property. You will then need to create an event handler for the Button Web control's Click eventrecall that this is accomplished by simply double-clicking the Button in the designer.
Now, in the Click event handler, you need to determine what message to display, based on the user's age. The code for this will look like
If age.Text < 21 then results.Text = name.Text & ", you are a youngster!" End If If age.Text >= 21 AND age.Text < 40 then results.Text = name.Text & ", you are an adult." End If If age.Text >= 40 then results.Text = name.Text & ", you are over the hill!" End If
Once you have entered the preceding source code into the Button Web control's Click event handler, save the ASP.NET Web page and test it by visiting it through a browser.
-
For more practice with the Web Matrix Project, take a moment to enhance the user interface of the FinancialCalculator.aspx Web page we created in this hour. A couple suggested enhancements, of many possible, include displaying the TextBox Web control titles in a more appealing font and adding some text at the top of the Web page explaining the purpose of the financial calculator.