Professional Documents
Culture Documents
2. Before you add the first TextBox Web control, though, first type in the title to
precede the TextBox Web control: Your height (in inches):. To enter this
text into the designer, simply place the cursor in the designer and start typing. If
needed, you can create a space by pressing the Enter key.
3. After you've typed in the label, next drag and drop a TextBox Web control from
the Toolbox onto the designer, placing it immediately after the text you just added
as shown below:
4.
5. Now let's add the second TextBox Web control. Start by moving your mouse
cursor after the TextBox Web control we just added and left-click. This will show
the cursor in the designer. You can then type in the title for the TextBox Web
control that we are about to enter. Specifically, enter the text Weight (in pounds):.
As before, after entering this text, drag and drop a TextBox Web control from the
Toolbox onto the designer, placing it immediately after the newly entered text.
6.
7. We need to add a submit button to our ASP.NET web page as well. To
accomplish this, drag and drop the Button Web control from the Toolbox to the
designer, placing it beneath the two TextBox Web controls.
8.
9. Take a moment to change the ID property to btnSubmit and the Text property to
Calculate BMI.
10. Next, click the first TextBox Web control, the one appearing after the text "Your
height (in inches):". Change the ID property to height. Finally, click on the
second TextBox Web control and change its ID property to weight.
11. Add a Label Web control with an ID LabelWebID and have the BMI calculation
displayed in this Label.
Add in the Source Code below for the button click event for BMICalculator.aspx
'Find out the person's height and weight
Dim h as Integer = height.Text
Dim w as Integer = weight.Text
'Calculate the person's BMI
Dim BMI as Double
BMI = (w / (h * h)) * 703
'Output the BMI value
LabelWebID.Text = "Your BMI is " & BMI
12. Now that we have added the needed Web controls, let's visit
BMICalculator.aspx through a browser. Go to the Debug menu and choose Start
Without Debugging. This will launch a web browser and direct it to
BMICalculator.aspx.
3.
4. Start with the first TextBox Web control. Because this Web control is used to
collect the user's name, let's set its ID property to name. To accomplish this,
follow these steps:
1.
Click the TextBox Web control, which will load its properties into the
Properties window.
2.
5. Repeat the same process for the second TextBox Web control, but set its ID
property to age.
6. Finally, click the Button Web control to set its properties. Start by setting the ID
property to btnSubmit and its Text property to "Click Me".
7. Let's take a moment to test this ASP.NET page so that we can observe the HTML
markup generated by the TextBox Web controls. Visit the ASP.NET page via
your web browser by going to the Debug menu and choosing Start Without
Debugging.
8.
9. Set the Label Web control's ID property to results and clear out the Text
property.
10.
11. Enter the following code to the button click event:
results.Text = "Hello, " & name.Text
results.Text &= ". You are " & age.Text & " years old."
8.
4.
3.
4. Start by clicking on the DropDownList Web control so that its properties are
loaded in the Properties window. Next, scroll down to the Items property. You
should see that the property value currently reads (Collection). If you click this
property value, a button with a pair of ellipses will appear to the right of
(Collection)
5. Go ahead and click this button; when you do so, a ListItem Collection Editor
dialog box will appear. This dialog box, allows you to add and remove list items
from the DropDownList Web control.
6.
7. To add a new list item, click the Add button.
8. After you click the Add button, a new entry is added to the left text box in the
ListItem Collection Editor dialog box. On the right side, the properties of the
newly added list item are displayed. As shown below, list items have four
properties: Enabled, Selected, Text, and Value.
9.
10. After you have added the three list items, the ListItem Collection Editor should
look similar to the one shown here:
11.
12. Finally, click OK on the ListItem Collection Editor dialog box. Note that the
DropDownList Web control in the designer has changed such that it shows the
word Vanilla as its selected list item.
13.
14. To facilitate this, start by adding a Label Web control to the DropDownList.aspx
web page and then specify the Label Web control's ID property as results. Also,
clear out the Text property.
15. Set the Button Web control's ID property to btnSubmit and its Text property to
Click Me. Then set the DropDownList Web control's ID property to flavors.
4.
5. Now simply set the RadioButton Web control's Text property to the appropriate
text. For the RadioButton.aspx web page, set the first RadioButton Web
control's Text property to Vanilla, the second's to Chocolate, and the third's to
Strawberry.
6. Therefore, to make the three RadioButton Web controls related (so that the user
can select only one flavor of the three), set the GroupName property for the three
RadioButton Web controls to the value flavors.
7.
8. Next, add a Label Web control after the Button Web control. After adding the
Label Web control, clear out its Text property and set its ID property to results.
9. Add in the following code for the button click event handler:
If vanilla.Checked then
results.Text = "You like Vanilla"
ElseIf chocolate.Checked Then
results.Text = "You like Chocolate"
ElseIf strawberry.Checked Then
results.Text = "You like Strawberry"
End If
4.