2. Chapter 7: Creating Web Applications 2 Objectives Create a Web application Build a Web form using ASP.NET 4.0 Set Web form properties Use the full screen view Add objects to a Web form Add a DropDownList object
3. Chapter 7: Creating Web Applications 3 Objectives Add a Calendar object Add a custom table for layout Validate data on Web forms Use the <br> tag in Visual Basic code Use string manipulation methods in the String class
4. Chapter 7: Creating Web Applications 4 Introduction Visual Studio allows you to create applications that can execute on the World Wide Web Visual Basic 2010 includes ASP.NET 4.0 technology, with which you can create a user interface and a form for a Web application A Web form is a page displayed in a Web browser such as Internet Explorer and Firefox that requests data from the user
6. Chapter 7: Creating Web Applications 6 Creating a Web Application A Web page that allows users to enter information on a Web form is considered a dynamic Web page because the user enters data and the Web page reacts to the data A Web server is a computer that stores Web documents and makes them available to people on the Internet The ASP.NET 4.0 technology used with Visual Basic 2010 creates an active server page (ASP)
7. Chapter 7: Creating Web Applications 7 Creating a Dynamic Web Site Using Visual Basic Start Visual Studio. Click the New Web Site button on the Standard toolbar In the center pane, click ASP.NET Web Site, if necessary. Name the chapter project application Mystic in the Location text box Click the OK button in the New Web Site dialog box
8. Chapter 7: Creating Web Applications 8 Creating a Dynamic Web Site Using Visual Basic
9. Customizing the Master Page In the Solution Explorer window, double-click Site.master to open the page Click View on the menu bar, point to Toolbars, and then click Formatting. Select the text at the top of the Site.master page MY ASP.NET APPLICATION. Type MYSTIC BED AND BREAKFAST to replace the original title. On the Formatting toolbar, click the Font Name tool, select Lucida Calligraphy, click the Font Size tool, and then select xx-large Chapter 7: Creating Web Applications 9
11. Customizing Navigation Buttons on the Master Template On the Site.master page, point to the two navigation buttons. Click theSmartTag and then click Edit Menu Items Click the About item in the list. In the Properties pane, change the Text property from About to Reservations Click the OK button, and then click a blank spot on the form to close the Menu Tasks menu Chapter 7: Creating Web Applications 11
13. Adding an Image Object In the Solution Explorer, double-click Default.aspx.Notice that the Default.aspx page has inherited the title and Reservations navigation page from the Site.master. Select the three lines starting with WELCOME TO ASP.NET! in the MainContentarea and press the DELETE key Drag the Image object from the Standard category in the Toolbox to the Web page under the navigation buttons. Resize the object so that it is 175 pixels by 150 pixels (px) In the Properties window, name the Image object by entering picMysticin its (ID) property. Specify which image to display by entering the Web address http://scsite.com/vb2010/ch7/images/bb.jpg as the ImageUrlproperty. You need Internet connectivity to view the image Chapter 7: Creating Web Applications 13
14. Adding an Image Object Chapter 7: Creating Web Applications 14
15. Entering Text Directly on the Web Form Click to the right of the Image object and type in all caps WELCOME TO THE OLDEST LIGHTHOUSE BED AND BREAKFAST directly on the Default.aspx page. Select the typed text and change the font size on the Formatting toolbar to x-large. Click a blank spot on the form to deselect the text To change the vertical alignment, select the text, click the Style property, and then click the ellipsis button to the right of the Style property in the Properties window. In the Category pane of the Modify Style dialog box, click Block. In the vertical-align drop box, select top Chapter 7: Creating Web Applications 15
16. Entering Text Directly on the Web Form Click the OK button, and then click a blank spot to deselect the text Click after the word BREAKFAST and press ENTER three times. Change the font size to medium in the Formatting toolbar. Enter the text High atop a cliff jutting into the clear, deep waters of Mystic Harbor, the Mystic Lighthouse beckons families in search of a secluded retreat from modern life. This unique bed and breakfast inn is one of the few surviving resident lighthouses in the country and is listed on the National Register of Historic Places. Chapter 7: Creating Web Applications 16
18. Adding a Table for Alignment on a Web Form In the Solution Explorer window, double-click About.aspx to create a Web form for the Reservations page. Delete the text in the MainContent area. Click below the navigation buttons in the MainContent area and type GUEST RESERVATION FORM:. Press ENTER. Click Table on the menu bar, and then click Insert Table. In the Size section of the Insert Table dialog box, change the number of Rows to 7 and the number of Columns to 3 Chapter 7: Creating Web Applications 18
19. Adding a Table for Alignment on a Web Form Click the OK button. To resize the columns, point to a column divider until a two-sided arrow appears. Drag the divider to change the column width. As you drag, a ScreenTip shows the width of the column in pixels. Resize the first column until it is 150 px wide. Resize the second column to 250 px wide Chapter 7: Creating Web Applications 19
20. Adding a Table for Alignment on a Web Form Chapter 7: Creating Web Applications 20
21. Adding TextBox and Button Objects On the About.aspx Web form, click in the first cell of the table and type Name: to enter text directly into the table. Open the Toolbox, drag a TextBoxobject from the Toolbox to the form, and then position the TextBox object in the second cell in the table. Resize the TextBox object to a width of 250 px.Name this TextBox object txtName using the (ID) property In the first cell in the second row of the table, type E-mail Address: to enter text directly into the table.Drag a TextBox object from the Toolbox to the form and then position the TextBox object in the second cell in the second row in the table. Resize the TextBox object to a width of 250 px.Name this TextBoxobject txtEmailusing the (ID) property Chapter 7: Creating Web Applications 21
22. Adding TextBox and Button Objects Chapter 7: Creating Web Applications 22
23. Chapter 7: Creating Web Applications 23 Adding CheckBox Objects On the third row, type Suite Selection: in the first cell.Dragthe CheckBoxobject from the Toolbox to the Web form, and then position it on the third row, second cell Name the CheckBox object by clicking to the right of its (ID) property in the Properties window and then entering chkSerenity. Change the Text property of the CheckBox object to Serenity Suite $220 In the Mystic Bed and Breakfast application, the Serenity suite is the most popular suite. This suite, therefore, should be checked when the form opens to save time for the user. To select the Serenity suite check box, change the Checked property for the object from False to True In the second column, fourth and fifth row of the table, add two more CheckBoxobjects named chkEvergreen and chkVineland, respectively. Change the Text property of the first CheckBox object to Evergreen Suite $170 and the second CheckBoxobject to Vineland Suite $155
25. Coding for Check Box Objects Chapter 7: Creating Web Applications 25
26. Chapter 7: Creating Web Applications 26 Adding a DropDownList Object In the sixth row of the table, type Night(s): in the first column. Drag the DropDownList object to the second column of the sixth row.Namethe DropDownListobject by clicking to the right of the (ID) property in the object’s Properties window and then typing ddlNights To fill the DropDownList object with list items, click the Smart Tag on the upper-right corner of the object Click Edit Items on the DropDownList Tasks menu
27. Chapter 7: Creating Web Applications 27 Adding a DropDownList Object Click the Add button. In the ListItem properties pane on the right side of the dialog box, click to the right of the Text property and enter 1 Click the Add button and enter 2 as its Text property. Repeat this step, entering the numbers 3 through 7 to specify the number of nights users can select in the DropDownList object. Click the OK button in the ListItemCollection Editor dialog box. Resize the DropDownList object to the width of a single digit, if necessary.To view the completed DropDownList object, run the application by clicking the Start Debugging button on the Standard toolbar. If necessary, click the Reservations navigation button to open the Reservations page in the browser. Click the list arrow on the DropDownList object in the Web page
29. Chapter 7: Creating Web Applications 29 Adding a Calendar Object Close the browser window. In the last row of the table, type Check-in Date:. Drag the Calendar object from the Toolbox to the Web form, and then position it on the form. In the (ID) property, name the Calendar object cldArrival Select the Calendar object, if necessary, and then click the Smart Tag on the upper-right corner of the Calendar object Click Auto Format on the Calendar Tasks menu. When the Auto Format dialog box opens, click the Colorful 2 scheme in the Select a scheme list
31. Specifying a Web Form Title Click the OK button to close the AutoFormat dialog box. In the Properties window of the Reservations Web form, click the drop-down box at the top and select DOCUMENT In the Properties window, scroll until the Title property is visible, and then click in the right column of the Title property. Enter the title Mystic Bed and Breakfast Reservation Form Chapter 7: Creating Web Applications 31
32. Specifying a Web Form Title Chapter 7: Creating Web Applications 32
34. Chapter 7: Creating Web Applications 34 Adding a Required Field Validator In the Toolbox, hide the Standard tools by clicking the filled triangle icon next to Standard. Expand the Validation tools by clicking the open triangle icon next to Validation Drag the RequiredFieldValidator to the right of the Name TextBox object Name the RequiredFieldValidator by typing rfvFirstName in its (ID)
35. Chapter 7: Creating Web Applications 35 Adding a Required Field Validator To specify that the rfvNameRequiredFieldValidator object validates the txtNameTextBox object, click to the right of the ControlToValidate property in the Properties window, click the list arrow, and then select txtName In the Properties window for the RequiredFieldValidator, change the ErrorMessageproperty to *Enter Name
37. Chapter 7: Creating Web Applications 37 Applying the Range Validator ControlToValidate property contains the name of the object you are validating MinimumValueproperty contains the smallest value in the range MaximumValueproperty contains the largest value in the range Type property matches the data type of the value, such as Integer or String ErrorMessageproperty explains to the user what value is requested
38. Applying the Compare Validator ControlToValidateproperty contains the name of the object that you are validating ControlToCompareproperty contains the name of the object that you are comparing to the ControlToValidate property ErrorMessageproperty contains a message stating that the value does not match Chapter 7: Creating Web Applications 38
39. Chapter 7: Creating Web Applications 39 Applying the Regular Expression Validator ControlToValidate property contains the name of the object that you are validating ErrorMessage property contains a message stating that the value does not match the valid format ValidationExpression property allows the user to select the format for the object
40. Chapter 7: Creating Web Applications 40 Applying the Regular Expression Validator Drag the RegularExpressionValidator object from the Toolbox to the right of the E-mail Address TextBox object in the table Name the RegularExpressionValidator by typing revEmail in its (ID) property Click to the right of the ControlToValidate property, click the list arrow, and then click txtEmail Change the ErrorMessage property to * Error E-mail Format
41. Chapter 7: Creating Web Applications 41 Applying the Regular Expression Validator To set txtEmail to validate that it contains a standard e-mail address, click to the right of the ValidationExpression property, and then click its ellipsis button. In the Regular Expression Editor dialog box, select Internet e-mail address in the Standard expressions list Click the OK button in the Regular Expression Editor dialog box. Run the application by clicking the Start Debugging button on the Standard toolbar. Enter an e-mail address without an @ symbol, such as Brit.world.net, and then press the ENTER key
42. Chapter 7: Creating Web Applications 42 Applying the Regular Expression Validator
44. Chapter 7: Creating Web Applications 44 Displaying the Validation Summary Control The ValidationSummary control lets you display validation error messages in a single location, creating a clean layout for the Web form You can use the ValidationSummary object to display all of the error messages in a different place, listing them in a blank area at the top or bottom of the form To use a ValidationSummary object, drag the object to the location on the Web page where you want the summary to appear
45. Chapter 7: Creating Web Applications 45 Using the <br> Tag in Visual Basic Code
52. Chapter 7: Creating Web Applications 52 Summary Create a Web application Build a Web form using ASP.NET 4.0 Set Web form properties Use the full screen view Add objects to a Web form Add a DropDownList object
53. Chapter 7: Creating Web Applications 53 Summary Add a Calendar object Add a custom table for layout Validate data on Web forms Use the <br> tag in Visual Basic code Use string manipulation methods in the String class