CST272 Project No. 2
Introduction to ASP.NET and C#
- Plato said that the ideal age of a man's wife is half his own age plus seven;
if that were true the ideal age of a woman's husband would be twice her age
minus 14. Write an ASP.NET application that calculates the ideal age
of a person's spouse. There will be an input TextBox and two Button
server controls. If the user clicks the "I am a male" Button, the
application will calculate the age of his wife; if the user clicks the "I
am a female" Button the application will calculate the age of her husband.
- Start a new ASP.NET Web Site project and add the following elements on the
Web page as follows:
- An appropriate title using a centered heading line (e.g. <h1>,
<h2>, etc.) should begin the page (use an embedded style sheet
in the <head> section to center this title)
- Find (on the Internet or some other location) or create a "banner style"
image appropriate to the application and place it also centered (also
using the embedded style sheet) following the heading line; this image
file should be placed in a folder named "images" within your Web Site
project folder
- Place a formatted horizontal rule (you may choose what type of formatting
but also place it in the embedded style sheet) following the image
- Create a table of four rows and one column placing the a TextBox server
control (include a descriptive label for the TextBox, e.g. "Enter your
age"), two Button server controls (one each for "I am a male" and "I am
a female"), and the Label server control each in separate cells; center
the table within the Web page (also using the embedded style sheet)
(download the Chapter 2 files from Brightspace again and
see the "WebForm2a.aspx" file to see how to center a table;
the "banner style" image can be centered the same way)
- Update the ID's (names) of the TextBox server control to "TextBoxAge",
the two Button server controls to "ButtonMale" and "ButtonFemale", and
the Label server control to "LabelResults"
- For either of the Buttons assign the input value from the "TextBoxAge"
TextBox to a variable of type
int
using the appropriate
Visual C# conversion method
- Then calculate the output age of the spouse and assign the result to
the Label server control with a descriptive label in the format "The
ideal age of your wife is 19" or "The ideal age of your husband is 24"
- You may receive a possible 9 out 10 points for the assignment
as presented in the textbook and above; for full credit (a maximum of 10
possible points), test during the numeric conversion of the input from the
"TextBoxAge" TextBox server control is numeric prior
to subsequent processing as follows:
- If the input is not numeric, use
try
... catch
processing to catch the exception and display an
appropriate error message to the user within the output Label server control
(you may have to go on-line to find out how to implement this functionality
but exception handling in C# is exactly the same as it is in Java)
- If the input age is numeric, continue with the specified processing
- The completed project, a ZIP file that contains the folder with all files
for the website, is due to Prof. Struck as an attachment to a
Brightspace
dropbox by 11:59 p.m. on the date specified in the course outline.