Home > Articles

Creating Our First ASP

This chapter is from the book

Creating the User Interface

Now that we've completed the design requirements phase and have decided what features our financial calculator will provide, as well as how the interface will appear to the user, it's time to actually start creating our ASP.NET Web page.

The first task is to create the user interface (or UI), which is considered the HTML portion of our ASP.NET Web page. To construct this UI, we'll add a TextBox Web control for each of the three inputs, as well as a Button Web control that, when clicked, will perform the necessary computations.

NOTE

After creating the user interface, we will turn our attention to writing the needed source code to perform the financial computations.

To start creating our user interface, launch the Web Matrix Project and create a new ASP.NET Web page named FinancialCalculator.aspx, making certain to use the Visual Basic .NET Language option (the default). Before we add any content to the HTML portion of our ASP.NET Web page, first take a moment to turn on glyphs, which are markers in the designer that indicate the location of HTML controls and Web controls. To turn on glyphs, go to the View menu and choose the Glyphs option.

With glyphs activated, you should see, in your Design tab, two yellow tags that mark the beginning and end of your form HTML control. Figure 3.3 contains a screenshot of the Web Matrix Project with glyphs enabled.

Figure 3.3Figure 3.3 Turning on glyphs uses markers to display invisible HTML controls and Web controls.

NOTE

If you do not see a Design tab for your ASP.NET Web page and instead see only Source and Preview tabs, you have the Web Matrix Project in Preview Mode and need to change to Design Mode. Refer back to the "Editing the HTML Content by Using the HTML Tab" section from Hour 2, "Understanding the ASP.NET Programming Model," for information on switching back to Design Mode.

Recall from our discussion in the previous hour that the Web Matrix Project automatically inserts a form HTML control in the HTML portion of your ASP.NET Web pages. The <form> tag is inserted in an HTML control because it has the runat="server" attribute, as can be seen by clicking the HTML tab (see Figure 3.4).

Figure 3.4Figure 3.4 The HTML portion of the ASP.NET Web page contains a form HTML control.

NOTE

The form HTML control is commonly referred to as a Web form or server-side form. The remainder of this book will refer to form HTML controls as either Web forms or server-side forms.

When creating an ASP.NET Web page that accepts user input—such as our financial calculator, which accepts three inputs from the user—it is required that the Web controls for user input (the TextBoxes, DropDownLists, CheckBoxes, and so on) be placed within a Web form. We will discuss why this needs to be done in Hour 9, "Web Form Basics."

TIP

Because our user input Web controls need to be within the Web form, it is important that we turn on glyphs so that we can see the Web form's start and finish. Then we can be sure that the controls we drop onto the designer from the Toolbox actually end up between the Web form's start and end tags, as opposed to before or after the Web form.

Adding the Three TextBox Web Controls

Let's start by adding the TextBox Web controls for our user's three inputs. First make sure that you are in the Design tab. Next place your mouse cursor between the Web form glyphs and click the left mouse button so that the designer receives focus and there is a flashing cursor between the Web form glyphs. Create some space between the Web form's start and end tags by hitting enter a few times. You should see something similar to Figure 3.5.

Figure 3.5Figure 3.5 Hit Enter to create some space between the Web form start and end tags.

Before we drag a TextBox Web control to the designer, let's first create the title for the textbox we're going to add. Because the first input is the amount of the mortgage, start by typing in this title: Mortgage Amount:.

Next we want to add a TextBox Web control after this title. To accomplish this, make sure that the Web Controls tab from the Toolbox is selected, and then drag a TextBox control from the Toolbox and drop it into the designer after the "Mortgage Amount:" title. Take a moment to make sure your screen looks similar to the screenshot shown in Figure 3.6.

Figure 3.6Figure 3.6 At this point you should have a title and a single textbox, both inside the Web form tags.

CAUTION

When dragging and dropping the TextBox Web control from the Toolbox, it is very important that the Web Control tab be selected so that you are indeed dragging and dropping TextBox Web controls. If the HTML Elements tab is selected on the Toolbox, you'll be placing standard HTML textboxes (textboxes without the runat="server" attribute present).

If you do not use TextBox Web controls, you will not be able to reference the values that the user entered in the TextBoxes in the source code portion of the ASP.NET Web page. Therefore, be certain that when dragging and dropping TextBoxes onto the designer for this exercise, you are dragging TextBox Web controls, not HTML textboxes.

Currently, the TextBox Web control we just added has its ID property set to TextBox1. Because we will later need to refer to this ID in order to determine the value of the beginning retirement balance entered by the user, let's choose an ID value that is representative of the data found within the TextBox. Specifically, change the ID property to loanAmount.

TIP

To change a Web control's ID property, click the Web control in the designer, which will load the Web control's properties in the Properties window in the lower right-hand corner. Scroll to the top of the Properties pane until you see the ID property. This is the property value that you should change. Note that in the list of properties in the Properties pane, the ID property is denoted as (ID).

Now let's add the second textbox, the mortgage's interest rate. Add it just as we did the previous TextBox Web control by first creating a title for the TextBox. Type in the title Annual Interest Rate:. Next drag and drop a TextBox Web control after this title and change the TextBox's ID property to rate.

Finally, add the third textbox, the duration of the mortgage. Start by adding the title Mortgage Length:, and then drag and drop a TextBox Web control after the title. Set this TextBox's ID to mortgageLength.

TIP

You might want to type in some text after each TextBox Web control to indicate the units that should be entered into the textbox. For example, after the "Annual Interest Rate" textbox, you might want to add a percent sign so that the user knows to enter this value as a percentage. Similarly, you might want to enter the word "years" after the "Mortgage Length" TextBox.

Figure 3.7 contains a screenshot of the Design tab after all three input TextBox Web controls have been added.

TIP

The screenshot in Figure 3.7 shows the TextBox Web control titles in the standard font. Feel free to change the font or the aesthetics of the HTML portion however you see fit. Just be sure to have three TextBox Web controls inside of the Web form.

Figure 3.7Figure 3.7 A screenshot of the Design tab, shown after all three TextBox Web controls have been added.

Adding the Compute Monthly Cost Button

After the user has entered inputs into the three TextBox Web controls, we want to be able to take that information and perform our financial calculation. Realize, though, that when the ASP.NET engine executed the ASP.NET Web page, it converted the TextBox Web controls into HTML <input> tags.

As we'll discuss in much greater detail in the next hour, "Dissecting Our First ASP.NET Web Page," when the users visit the FinancialCalculator.aspx ASP.NET Web page via their browsers, they are receiving HTML that contains a <form> tag and, within it, three <input> textbox tags. This HTML markup, when rendered by a browser, displays three textboxes, as shown in Figure 3.7. In order for the calculation to take place, the inputs entered by the user must be submitted back to our ASP.NET Web page (FinancialCalculator.aspx). Once our ASP.NET Web page receives these user-entered values, it can perform the financial computation and return the results.

In order for an HTML form to be submitted, the user needs a button that, when clicked, causes the form to be submitted. We can add such a button by adding a Button Web control to our ASP.NET Web page.

NOTE

We will discuss the specifics involved with collecting and computing user input in Hour 9, "Web Form Basics."

To add a Button Web control, first ensure that the Web Controls tab in the Toolbox is selected. Then drag the Button Web control from the Toolbox onto the designer, dropping it after the last input title and textbox.

When dropping a Button Web control onto the designer, the button's caption reads "Button." To change this, click the button and then in the Properties pane change the Text property from Button to Compute Monthly Cost. This will change the caption on your button to "Compute Monthly Cost." Also, while in the Properties pane, change the button's ID property—listed in the property pane as (ID)—from the default Button1 to performCalc.

Take a moment to make sure that your screen looks similar to the screenshot in Figure 3.8.

Figure 3.8Figure 3.8 A Button Web control has been added.

Creating a Label Web Control for the Output

The final piece we need to add to our user interface is a Label Web control that will to display the output of our financial calculation. Because the Label Web control will display the output (the amount of money the mortgage costs per month), the Web page's final result will appear wherever you place the Web control. Therefore, if you want the output to appear at the bottom of your ASP.NET Web page, simply drag and drop a Label Web control after the existing content in the designer. If you want the output to appear at the top of the Web page, place it before the existing content in the designer.

To add the Label Web control, drag and drop it from the Toolbox and onto the designer. Once you have added the Label Web control, you will see that it displays the message "Label." The Label Web control displays the value of its Text property, which is configurable via the Properties pane. Figure 3.9 is a screenshot of the designer with the Label Web control added.

Figure 3.9Figure 3.9 A Label Web control has been added to the ASP.NET Web page.

Because we don't want this label to display any content until the user has entered their three inputs and the calculation has been performed, clear out the Label's Text property. To clear out a property value for the Label Web control, first click the Label Web control so that its properties are loaded in the Properties pane. Then, in the Properties pane, locate the Text property and erase the Text property value by clicking the Text property's value and hitting backspace until all of the characters have been erased.

Once you clear out the Label's Text property, the designer will show the Label Web control as its ID property, enclosed by brackets. Currently, the Label Web control's ID property is Label1, meaning that in the designer you should see the Label Web control displayed as: [Label1]. Go ahead and change the ID property of the Label Web control from Label1 to results, which should change the label's display in the designer from [Label1] to [results]. Figure 3.10 shows a screenshot of the designer after the Label Web control's property has been changed to results.

Figure 3.10Figure 3.10 The Label Web control's ID has been changed to results.

Completing the User Interface

At this point we have added the vital pieces of the user interface. This was accomplished using the Web Matrix Project's WYSIWYG editor in a fraction of the time it would have taken to enter the HTML markup and Web control syntax manually.

NOTE

To fully appreciate the amount of HTML markup the Web Matrix Project generated for us automatically, click the HTML tab.

If you want to add additional user interface elements at this time, perhaps a bold, centered title at the top of the Web page or a brief set of instructions for the user, feel free to do so.

Now that we have created the HTML portion of the ASP.NET Web page, we are ready to create the source code portion in the next section.

TIP

HTML markup and Web controls not used for user input may appear either within the Web form tags or outside of these tags. The only things that must be placed within the Web form tags are the Web controls that collect user input (the TextBoxes and Button).

InformIT Promotional Mailings & Special Offers

I would like to receive exclusive offers and hear about products from InformIT and its family of brands. I can unsubscribe at any time.

Overview


Pearson Education, Inc., 221 River Street, Hoboken, New Jersey 07030, (Pearson) presents this site to provide information about products and services that can be purchased through this site.

This privacy notice provides an overview of our commitment to privacy and describes how we collect, protect, use and share personal information collected through this site. Please note that other Pearson websites and online products and services have their own separate privacy policies.

Collection and Use of Information


To conduct business and deliver products and services, Pearson collects and uses personal information in several ways in connection with this site, including:

Questions and Inquiries

For inquiries and questions, we collect the inquiry or question, together with name, contact details (email address, phone number and mailing address) and any other additional information voluntarily submitted to us through a Contact Us form or an email. We use this information to address the inquiry and respond to the question.

Online Store

For orders and purchases placed through our online store on this site, we collect order details, name, institution name and address (if applicable), email address, phone number, shipping and billing addresses, credit/debit card information, shipping options and any instructions. We use this information to complete transactions, fulfill orders, communicate with individuals placing orders or visiting the online store, and for related purposes.

Surveys

Pearson may offer opportunities to provide feedback or participate in surveys, including surveys evaluating Pearson products, services or sites. Participation is voluntary. Pearson collects information requested in the survey questions and uses the information to evaluate, support, maintain and improve products, services or sites, develop new products and services, conduct educational research and for other purposes specified in the survey.

Contests and Drawings

Occasionally, we may sponsor a contest or drawing. Participation is optional. Pearson collects name, contact information and other information specified on the entry form for the contest or drawing to conduct the contest or drawing. Pearson may collect additional personal information from the winners of a contest or drawing in order to award the prize and for tax reporting purposes, as required by law.

Newsletters

If you have elected to receive email newsletters or promotional mailings and special offers but want to unsubscribe, simply email information@informit.com.

Service Announcements

On rare occasions it is necessary to send out a strictly service related announcement. For instance, if our service is temporarily suspended for maintenance we might send users an email. Generally, users may not opt-out of these communications, though they can deactivate their account information. However, these communications are not promotional in nature.

Customer Service

We communicate with users on a regular basis to provide requested services and in regard to issues relating to their account we reply via email or phone in accordance with the users' wishes when a user submits their information through our Contact Us form.

Other Collection and Use of Information


Application and System Logs

Pearson automatically collects log data to help ensure the delivery, availability and security of this site. Log data may include technical information about how a user or visitor connected to this site, such as browser type, type of computer/device, operating system, internet service provider and IP address. We use this information for support purposes and to monitor the health of the site, identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents and appropriately scale computing resources.

Web Analytics

Pearson may use third party web trend analytical services, including Google Analytics, to collect visitor information, such as IP addresses, browser types, referring pages, pages visited and time spent on a particular site. While these analytical services collect and report information on an anonymous basis, they may use cookies to gather web trend information. The information gathered may enable Pearson (but not the third party web trend services) to link information with application and system log data. Pearson uses this information for system administration and to identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents, appropriately scale computing resources and otherwise support and deliver this site and its services.

Cookies and Related Technologies

This site uses cookies and similar technologies to personalize content, measure traffic patterns, control security, track use and access of information on this site, and provide interest-based messages and advertising. Users can manage and block the use of cookies through their browser. Disabling or blocking certain cookies may limit the functionality of this site.

Do Not Track

This site currently does not respond to Do Not Track signals.

Security


Pearson uses appropriate physical, administrative and technical security measures to protect personal information from unauthorized access, use and disclosure.

Children


This site is not directed to children under the age of 13.

Marketing


Pearson may send or direct marketing communications to users, provided that

  • Pearson will not use personal information collected or processed as a K-12 school service provider for the purpose of directed or targeted advertising.
  • Such marketing is consistent with applicable law and Pearson's legal obligations.
  • Pearson will not knowingly direct or send marketing communications to an individual who has expressed a preference not to receive marketing.
  • Where required by applicable law, express or implied consent to marketing exists and has not been withdrawn.

Pearson may provide personal information to a third party service provider on a restricted basis to provide marketing solely on behalf of Pearson or an affiliate or customer for whom Pearson is a service provider. Marketing preferences may be changed at any time.

Correcting/Updating Personal Information


If a user's personally identifiable information changes (such as your postal address or email address), we provide a way to correct or update that user's personal data provided to us. This can be done on the Account page. If a user no longer desires our service and desires to delete his or her account, please contact us at customer-service@informit.com and we will process the deletion of a user's account.

Choice/Opt-out


Users can always make an informed choice as to whether they should proceed with certain services offered by InformIT. If you choose to remove yourself from our mailing list(s) simply visit the following page and uncheck any communication you no longer want to receive: www.informit.com/u.aspx.

Sale of Personal Information


Pearson does not rent or sell personal information in exchange for any payment of money.

While Pearson does not sell personal information, as defined in Nevada law, Nevada residents may email a request for no sale of their personal information to NevadaDesignatedRequest@pearson.com.

Supplemental Privacy Statement for California Residents


California residents should read our Supplemental privacy statement for California residents in conjunction with this Privacy Notice. The Supplemental privacy statement for California residents explains Pearson's commitment to comply with California law and applies to personal information of California residents collected in connection with this site and the Services.

Sharing and Disclosure


Pearson may disclose personal information, as follows:

  • As required by law.
  • With the consent of the individual (or their parent, if the individual is a minor)
  • In response to a subpoena, court order or legal process, to the extent permitted or required by law
  • To protect the security and safety of individuals, data, assets and systems, consistent with applicable law
  • In connection the sale, joint venture or other transfer of some or all of its company or assets, subject to the provisions of this Privacy Notice
  • To investigate or address actual or suspected fraud or other illegal activities
  • To exercise its legal rights, including enforcement of the Terms of Use for this site or another contract
  • To affiliated Pearson companies and other companies and organizations who perform work for Pearson and are obligated to protect the privacy of personal information consistent with this Privacy Notice
  • To a school, organization, company or government agency, where Pearson collects or processes the personal information in a school setting or on behalf of such organization, company or government agency.

Links


This web site contains links to other sites. Please be aware that we are not responsible for the privacy practices of such other sites. We encourage our users to be aware when they leave our site and to read the privacy statements of each and every web site that collects Personal Information. This privacy statement applies solely to information collected by this web site.

Requests and Contact


Please contact us about this Privacy Notice or if you have any requests or questions relating to the privacy of your personal information.

Changes to this Privacy Notice


We may revise this Privacy Notice through an updated posting. We will identify the effective date of the revision in the posting. Often, updates are made to provide greater clarity or to comply with changes in regulatory requirements. If the updates involve material changes to the collection, protection, use or disclosure of Personal Information, Pearson will provide notice of the change through a conspicuous notice on this site or other appropriate way. Continued use of the site after the effective date of a posted revision evidences acceptance. Please contact us if you have questions or concerns about the Privacy Notice or any objection to any revisions.

Last Update: November 17, 2020