Presentation is loading. Please wait.

Presentation is loading. Please wait.

21 ASP.NET 2.0, Web Forms and Web Controls.

Similar presentations


Presentation on theme: "21 ASP.NET 2.0, Web Forms and Web Controls."— Presentation transcript:

1 21 ASP.NET 2.0, Web Forms and Web Controls

2 A fair question should be followed by a deed in silence.
If any man will draw up his case, and put his name at the foot of the first page, I will give him an immediate reply. Where he compels me to turn over the sheet, he must wait my leisure. Lord Sandwich Rule One: Our client is always right Rule Two: If you think our client is wrong, see Rule One. Anonymous A fair question should be followed by a deed in silence. Dante Alighieri

3 You will come here and get books that will open your eyes, and your ears, and your curiosity, and turn you inside out or outside in. Ralph Waldo Emerson

4 OBJECTIVES In this chapter you will learn:
Web application development using ASP.NET. To create Web Forms. To create ASP.NET applications consisting of multiple Web Forms. To maintain state information about a user with session tracking and cookies. To use the Web Site Administration Tool to modify Web application configuration settings. To control user access to Web applications using forms authentication and ASP.NET login controls. To use databases in ASP.NET applications. To design a master page and content pages to create a uniform look-and-feel for a Web site.

5 21.1 Introduction 21.2 Simple HTTP Transactions 21.3 Multitier Application Architecture 21.4 Creating and Running a Simple Web-Form Example Examining an ASPX File Examining a Code-Behind File Relationship Between an ASPX File and a Code- Behind File How the Code in an ASP.NET Web Page Executes Examining the XHTML Generated by an ASP.NET Application Building an ASP.NET Web Application 21.5 Web Controls Text and Graphics Controls AdRotator Control Validation Controls

6 21.6 Session Tracking Cookies Session Tracking with HttpSessionState 21.7 Case Study: Connecting to a Database in ASP.NET Building a Web Form That Displays Data from a Database Modifying the Code-Behind File for the Guestbook Application 21.8 Case Study: Secure Books Database Application Examining the Completed Secure Books Database Application Creating the Secure Books Database Application 21.9 Wrap-Up 21.10 Web Resources

7 Fig. 21. 1 | Client interacting with Web server
Fig | Client interacting with Web server. Step 1: The GET request.

8 Fig. 21. 2 | Client interacting with Web server
Fig | Client interacting with Web server. Step 2: The HTTP response.

9 Fig. 21.3 | Three-tier architecture.

10 Outline WebTime.aspx

11 Portability Tip 21.1 The same Web control can map to different XHTML elements, depending on the client browser and the Web control’s property settings.

12 Outline WebTime.aspx.cs (1 of 2)

13 Outline WebTime.aspx.cs (2 of 2)

14 Performance Tip 21.1 Once an instance of the Web page has been created, multiple clients can use it to access the page—no recompilation is necessary. The project will be recompiled only when you modify the application; changes are detected by the runtime environment, and the project is recompiled to reflect the altered content.

15 Outline WebTime.html

16 Fig. 21.7 | Creating an ASP.NET Web Site in Visual Web Developer.

17 Fig. 21.8 | Solution Explorer window for project WebTime.
Code-behind file Properties Refresh Nest Related Files View Code View Designer Copy Web Site ASP.NET Configuration ASPX file Fig | Solution Explorer window for project WebTime.

18 Fig. 21.9 | Toolbox in Visual Web Developer.

19 Fig. 21.10 | Source mode of the Web Forms Designer.
Design mode button Source mode button Fig | Source mode of the Web Forms Designer.

20 Fig. 21.11 | Design mode of the Web Forms Designer.
Cursor Cursor’s current location Fig | Design mode of the Web Forms Designer.

21 Fig. 21. 12 | Code-behind file for Default
Fig | Code-behind file for Default.aspx generated by Visual Web Developer.

22 Portability Tip 21.2 Absolute positioning is discouraged, because pages designed in this manner may not render correctly on computers with different screen resolutions and font sizes. This could cause absolutely positioned elements to overlap each other or display off-screen, requiring the client to scroll to see the full page content.

23 Fig. 21.13 | WebTime.aspx after inserting text and a new paragraph.
Cursor position after inserting text and a new paragraph by pressing Enter Block Format drop-down list Fig | WebTime.aspx after inserting text and a new paragraph.

24 Label Fig | WebTime.aspx after adding a Label and setting its properties.

25 Fig. 21.15 | Commonly used Web controls.

26 Outline WebControls.aspx (1 of 6)

27 Outline WebControls.aspx (2 of 6)

28 Outline WebControls.aspx (3 of 6)

29 Outline WebControls.aspx (4 of 6)

30 Outline WebControls.aspx (5 of 6)

31 Outline (6 of 6) WebControls.aspx Image control TextBox control
DropDownList control HyperLink control RadioButtonList control Button control WebControls.aspx (6 of 6)

32 Fig. 21.17 | DropDownList Tasks smart tag menu.

33 Outline FlagRotator.aspx (1 of 2)

34 Outline (2 of 2) FlagRotator.aspx (a) (b) AdRotator image
AlternativeText displayed in a tooltip (b) (c) FlagRotator.aspx (2 of 2)

35 Outline AdRotator Information.xml (1 of 4)

36 Outline AdRotator Information.xml (2 of 4)

37 Outline AdRotator Information.xml (3 of 4)

38 Outline AdRotator Information.xml (4 of 4)

39 Outline Validation.aspx (1 of 6)

40 Outline Validation.aspx (2 of 6)

41 Outline Validation.aspx (3 of 6)

42 Outline Validation.aspx (4 of 6)

43 Outline (a) (b) Validation.aspx (5 of 6)

44 Outline (c) (d) Validation.aspx (6 of 6)

45 Outline Validation.aspx.cs (1 of 2)

46 Outline Validation.aspx.cs (2 of 2)

47 Performance Tip 21.2 Setting EnableViewState to False reduces the amount of data passed to the Web server with each request.

48 Outline Validation.html (1 of 9)

49 Outline Validation.html (2 of 9)

50 Outline Validation.html (3 of 9)

51 Outline Validation.html (4 of 9)

52 Outline Validation.html (5 of 9)

53 Outline Validation.html (6 of 9)

54 Outline Validation.html (7 of 9)

55 Outline Validation.html (8 of 9)

56 Outline Validation.html (9 of 9)

57 Portability Tip 21.3 Clients may disable cookies in their Web browsers to ensure that their privacy is protected. Such clients will experience difficulty using Web applications that depend on cookies to maintain state information.

58 Outline Options.aspx (1 of 4)

59 Outline Options.aspx (2 of 4)

60 Outline (a) Options.aspx (3 of 4) (b)

61 Outline (c) Options.aspx (4 of 4) (d)

62 Outline Options.aspx.cs (1 of 3)

63 Outline Options.aspx.cs (2 of 3)

64 Outline Options.aspx.cs (3 of 3)

65 Outline Recommendations .aspx (1 of 2)

66 Outline Recommendations .aspx (2 of 2)

67 Outline Recommendations .aspx.cs (1 of 2)

68 Outline Recommendations .aspx.cs (2 of 2)

69 Fig. 21.27 | HttpCookie properties.

70 Outline Options.aspx (1 of 4)

71 Outline Options.aspx (2 of 4)

72 Outline (a) Options.aspx (3 of 4) (b)

73 Outline (c) Options.aspx (4 of 4) (d)

74 Software Engineering Observation 21.1
A Web Form should not use instance variables to maintain client state information, because each new request or postback, is handled by a new instance of the page. Web Forms should maintain client state information in HttpSessionState objects, because such objects are specific to each client.

75 Outline Options.aspx.cs (1 of 3)

76 Outline Options.aspx.cs (2 of 3)

77 Outline Options.aspx.cs (3 of 3)

78 Software Engineering Observation 21.2
One of the primary benefits of using HttpSessionState objects (rather than cookies) is that HttpSessionState objects can store any type of object (not just Strings) as attribute values. This provides you with increased flexibility in determining the type of state information to maintain for clients.

79 Fig. 21.30 | HttpSessionState properties.

80 Outline Recommendations .aspx (1 of 2)

81 Outline Recommendations .aspx (2 of 2)

82 Outline Recommendations .aspx.cs (1 of 2)

83 Outline Recommendations .aspx.cs (2 of 2)

84 Fig. 21.33 | Guestbook application GUI in Design mode.
GridView control Fig | Guestbook application GUI in Design mode.

85 Fig. 21.34 | Change Data Source dialog in Visual Web Developer.

86 Fig. 21.35 | Configuring the SELECT statement used by the SqlDataSource to retrieve data.

87 Fig. 21.36 | Previewing the data retrieved by the SqlDataSource.

88 SqlDataSource control
Fig | Design mode displaying SqlDataSource control for a GridView.

89 Fig. 21.38 | Removing the MessageID column from the GridView.

90 Fig. 21.39 | Setting up INSERT parameters based on control values.

91 Outline Guestbook.aspx (1 of 7)

92 Outline Guestbook.aspx (2 of 7)

93 Outline Guestbook.aspx (3 of 7)

94 Outline Guestbook.aspx (4 of 7)

95 Outline Guestbook.aspx (5 of 7)

96 Outline (a) Guestbook.aspx (6 of 7)

97 Outline (b) Guestbook.aspx (7 of 7)

98 Outline Guestbook.aspx.cs (1 of 2)

99 Outline Guestbook.aspx.cs (2 of 2)

100 Fig. 21.42 | Login.aspx page of the secure books database application.

101 Fig. 21.43 | CreateNewUser.aspx page of the secure book database application.

102 Fig. 21.44 | Message displayed to indicate that a user account was created successfully.

103 Fig. 21.45 | Books.aspx displaying books by Harvey Deitel (by default).

104 Fig. 21.46 | Books.aspx displaying books by Andrew Goldberg.

105 Fig. 21.47 | Logging in using the Login control.

106 Fig. 21.48 | Error message displayed for an unsuccessful login attempt using the Login control.

107 Fig. 21.49 | Web Site Administration Tool for configuring a Web application.

108 Fig. 21.50 | Security page of the Web Site Administration Tool.

109 Fig. 21. 51 | Choosing the type of authentication used by an ASP
Fig | Choosing the type of authentication used by an ASP.NET Web application.

110 Fig. 21.52 | Main page of the Web Site Administration Tool after enabling forms authentication.

111 Fig. 21.53 | Add New Access Rule page used to configure directory access.

112 Fig. 21.54 | Master page in Source mode.

113 Fig. 21.55 | Master page in Design mode.

114 Outline Bug2Bug.master (1 of 2)

115 Outline Bug2Bug.master (2 of 2)

116 Fig. 21.57 | Content page CreateNewUser.aspx in Source mode.

117 Fig. 21.58 | Content page CreateNewUser.aspx in Design mode.

118 Outline CreateNewUser.aspx (1 of 3)

119 Outline CreateNewUser.aspx (2 of 3) (a) (b)

120 Outline (c) CreateNewUser.aspx (3 of 3)

121 Outline Login.aspx (1 of 2)

122 Outline (a) (b) Login.aspx (2 of 2)

123 Fig. 21.61 | Authors DataTable in the Dataset Designer.

124 Fig. 21.62 | Query Builder for designing a query that selects books written by a particular author.

125 Fig. 21.63 | Dataset Designer after adding the TitlesTableAdapter.

126 Fig. 21.64 | Choosing a business object for an ObjectDataSource.

127 Fig. 21.65 | Choosing a data method of a business object for use with an ObjectDataSource.

128 Fig. 21.66 | Choosing a data source for a DropDownList.

129 Fig. 21.67 | Choosing the data source for a parameter in a business object’s data method.

130 Fig. 21.68 | Completed Books.aspx in Design mode.

131 Outline Books.aspx (1 of 5)

132 Outline Books.aspx (2 of 5)

133 Outline (a) Books.aspx (3 of 5)

134 Outline (b) Books.aspx (4 of 5)

135 Outline (c) Books.aspx (5 of 5)


Download ppt "21 ASP.NET 2.0, Web Forms and Web Controls."

Similar presentations


Ads by Google