1 106762962 Chapter 1 An introduction to ASP.NET web programming Objectives Applied Start a web application by entering its URL into your web browser. Knowledge Describe these terms: web application, web page, web form, client, server, HTTP, HTML, HTTP request, HTTP response, postback, and round trip. Name the software component that’s required on the client of any web application, and name the two software components that are usually required on the server of any web application. Distinguish between static web pages and dynamic web pages. Explain how dynamic web pages are processed by the web server. Describe the four components of a URL, and describe what happens when you omit the file name from a URL when you request a web page. Explain why HTTP is called a stateless protocol, and list the four features for managing state that are provided by ASP.NET. List the software components that you need on your own PC if you want to develop and run ASP.NET web applications, including database applications. Name the two main components of the .NET Framework and describe the purpose of each. Describe the three types of environments that can be used for developing ASP.NET applications. Describe the aspx files, code-behind files, and other classes that make up an ASP.NET web application. In general terms, describe the way that the files for an ASP.NET page are compiled and run when the page is requested for the first time, and when the page receives subsequent requests. 2 106762962 Chapter 2 How to develop a one-page web application Objectives Applied Given the specifications for a web form, use the Web Forms Designer to design the form. Given the specifications for a one-page web application, use the Code Editor to write the C# code for the web form. Run and test the web applications that you develop. Knowledge Describe the way the files are organized in a file-system web site. Explain what the target framework is for an ASP.NET 4 application. Describe the uses of Visual Studio’s Web Forms Designer and Code Editor. Describe the three different views of the Web Forms Designer. Explain what a code snippet is and list three ways you can use them. Distinguish between web server controls, HTML server controls, and validation controls. Describe the way controls are displayed when you use flow layout. Describe the use of the AutoPostBack, CausesValidation, and EnableViewState properties for a web server control. Describe the use of the Load event for a web page. Describe the use of the IsPostBack and IsValid properties for a web page. Describe the use of the Click, TextChanged, CheckedChanged, and SelectedIndexChanged events for a web server control. Describe how the HTML that’s sent to a browser handles view state and user input. 3 106762962 Chapter 3 How to develop a multi-page web application Objectives Applied Given the specifications for a multi-page web application that uses an Access data source to get data, design, code, and test the application. To transfer to another page within a web application, be able to use the Transfer method, the Redirect method, or cross-page posting. To refer to pages or other files within an application, be able to use either absolute or relative URLs. Knowledge Describe the contents of these special folders for ASP.NET applications: App_Code and App_Data. Describe two ways that you can use an existing class with a new web application. Describe the main folders and files that are added to a web site by default when you use the ASP.NET Web Site template to start the web site. In general terms, describe the procedure for renaming a web form file as well as the class that contains the code for the web form. Distinguish between the Transfer method of the HttpServerUtility class, the Redirect and RedirectPermanent methods of the HttpResponse class, and cross-page posting. Distinguish between absolute and relative URLs. Describe an Access data source. In general terms, explain how the AccessDataSource, DataView, and DataRowView classes can be used to get data from a data source. Describe how session state objects, session IDs, and cookies are used to track the state of each user of a web application. 4 106762962 Chapter 4 How to test and debug an ASP.NET application Objectives Applied Test a file-system web site with the ASP.NET development server or IIS. Create and test a local IIS web site. Test a web site using more than one browser. Use the debugging techniques presented in this chapter to determine the cause of runtime or logical errors in any of the applications you develop. Knowledge Explain how a file-system web site can be run under IIS. Describe how you can test your applications for concurrency errors. Describe the conditions under which an Exception Assistant dialog box is displayed. Distinguish between breakpoints and tracepoints. Describe the differences between the three Step commands that you can use to control the execution of an application: Step Into, Step Over, and Step Out. Describe the primary use of the Autos, Locals, and Watch windows. Describe the use of the Trace feature of ASP.NET. Describe the use of messages that are written directly to the HTTP output stream. 5 106762962 Chapter 5 A crash course in HTML and CSS Objectives Applied Given the content and structure for a web page, code the HTML needed to implement the page. Use Design view to format an element or change an element’s margins or padding. Given an external style sheet, apply its styles to the forms of an application. Given the specifications for the styles used by an application, create an external style sheet that defines those styles. Use the Apply Styles, CSS Properties, and Manage Styles windows to apply and work with any of the styles that are available to a form. Knowledge Describe each of these terms as they relate to HTML documents: element, start tag, content, end tag, self-closing tag, attribute. Describe the use of the CodeFile attribute in the Page directive for an HTML document. Distinguish between a block element and an inline element. Describe the use of these block elements: div, h1, h2, h3, p. Describe the use of these inline elements: i, b, br, span. Describe three ways to include CSS in a web page. Describe the two main advantages you get from using external style sheets. Describe the basic parts of a CSS rule set. Describe how you code CSS selectors for elements, IDs, and classes. 6 106762962 Chapter 6 How to work with server controls Objectives Applied Given the specifications for a web form that uses any of the server controls presented in this chapter, design and code the form. Knowledge Describe the normal coding technique for handling control events. Describe the way ASP.NET provides for setting access keys for controls and for setting the default focus and default button for forms. Describe the differences between buttons, link buttons, and image buttons. Describe the use of the e argument when working with an image button control. Describe the use of the Command event and the CommandName property of a button control for processing a group of button controls. Describe the differences between the way check box controls and radio button controls work, including the difference in when the CheckedChanged event occurs. Explain how the items in any of the list controls are stored and how you refer to these items in code. Explain the purpose of the ListItem Collection Editor and describe when you might use it. 7 106762962 Chapter 7 How to use the validation controls Objectives Applied Given the data validation requirements for a web form, use any of the validation controls presented in this chapter to implement that validation. Create your own regular expression for use with a regular expression validator. Knowledge Describe the use of each of the six validation controls provided by ASP.NET. Describe the use of the ErrorMessage and Text properties of a validation control. Explain how ASP.NET processes validation controls. Describe two types of validation that can be done by a required field validator. Describe three types of validation that can be done by a compare validator. Describe the use of validation groups. Describe the use of the IsValid property of a page and the Validate method of a page. List two common uses for the regular expression validator. Describe the use of a custom validator. 8 106762962 Chapter 8 How to manage state Objectives Applied Given the specifications for an application that requires any of the state management techniques presented in this chapter, design and develop the application. Use the web.config file to set session state options. Use a cookie or a query string to pass information from one page to another. Knowledge Describe the uses of view state, session state, and application state. Explain how you enable view state for selected controls. Describe the events that are typically used to retrieve and save session state items that are used by two or more event handlers. Describe the use of the Cookieless attribute for the session state element in the web.config file. Describe when an application begins and ends. Explain how a project’s global.asax file is used with application state. Describe the use of cookies. Describe the use of query strings. 9 106762962 Chapter 9 How to use master pages Objectives Applied Use a master page to provide the elements that are the same for a set of content pages. Use a parent master page to provide the elements that are the same for a set of content pages and child master pages to provide the elements that are the same for subsets of content pages in that set. Knowledge In general terms, describe the use of master pages, content pages, content placeholders, master page events, and nested master pages. In general terms, describe the way a content page uses (1) Content elements and (2) the MasterPageFile attribute of its Page directive. Describe the procedure for converting a regular ASP.NET page to a content page. In general terms, describe the procedure for accessing master page controls from a content page. 10 106762962 Chapter 10 How to use site navigation Objectives Applied Use any of the site navigation features to make it easier for users to navigate through the pages of a web site. Knowledge Describe the use of a SiteMapDataSource control and its related web.sitemap file. Describe the use of the TreeView, Menu, and SiteMapPath controls. 11 106762962 Chapter 11 How to use themes Because the goal of this book is to teach you the programming skills that you need for developing web applications, not the design skills, the objectives that follow are minimal. In general, they assume that you will only have to know how to apply themes, not develop themes. To further simplify, the objectives assume that you will only apply themes to an entire application, so you don’t need to know how to apply or remove themes and skins to or from individual pages or controls. Beyond that, though, you should have a general understanding of what themes can do, so the knowledge objectives have that focus. Objectives Applied Given the theme for an application, apply it to a web site. Knowledge Describe the three components of a theme. Describe the difference between when customization themes and style sheet themes are applied. 12 106762962 Chapter 12 An introduction to database programming Objectives Knowledge Explain how a table in a relational database is organized. Explain how the tables in a relational database are related. Describe the use of these SQL statements: Select, Insert, Update, and Delete. Describe the use of these ADO.NET components: data adapter, command, connection, data reader, dataset, data table. Describe concurrency, optimistic concurrency control, and “last in wins.” 13 106762962 Chapter 13 How to use SQL data sources Objectives Applied Use a SQL data source to get the data that an application requires. Use the Query Builder to create the Select statement for a SQL data source. Use a DataList control to present the data that’s retrieved by a SQL data source. Use a list control such as a drop-down list to present the data that’s retrieved by a SQL data source. Create a SQL data source that can be used to update the data in a database. Knowledge Describe how a select parameter that gets its value from a control is defined. Describe how you use the Eval and Bind methods within the templates of a DataList control to bind the template controls to columns of a data source. Describe the additional code that’s generated for a data source that can update the database. Explain when you might change the DataSourceMode attribute of a data source from its default setting of DataSet to DataReader. Explain when you might want to store the data that’s retrieved by a data source in the server’s cache memory. 14 106762962 Chapter 14 How to use the GridView control Objectives Applied Use a GridView control with bound fields to format and display the data in a data source. Use a GridView control to update the data in a data source. Use events raised by a GridView control to check for exceptions. Use the SQL data source for a GridView control to insert a row into the database. Use template fields and validation controls with a GridView control. Knowledge Describe the basic functions that are provided by the GridView control. Describe the difference between a bound field and a template field. Explain what a command field is and how it’s used in a GridView control. Explain what the before-action and after-action events of a GridView control are typically used for. Describe how you can provide for adding rows to a GridView control. 15 106762962 Chapter 15 How to use the DetailsView and FormView controls Objectives Applied Use a DetailsView control to display the data in a single row of a data source. Use a DetailsView control to edit, delete, and insert rows in a data source. Use templates to control the appearance of the fields in a DetailsView control. Use a FormView control to display the data in a single row of a data source. Use a FormView control to edit, delete, and insert rows in a data source. Knowledge Describe the three modes of the DetailsView control. Describe the basic functions of the DetailsView and FormView controls. Explain what the before-action and after-action events of a DetailsView control are typically used for. Describe the templates that you can use to control the appearance of a DetailsView control. Describe how the DetailsView and FormView controls differ. Describe the templates that are generated for a FormView control. Explain what a Master/Detail page is and how you develop one using a DetailsView or FormView control. 16 106762962 Chapter 16 How to use the ListView and DataPager controls Objectives Applied Use a ListView control to display, format, and sort the data for the rows of a data source in grid layout. Use a ListView control to display, format, and group the data for the rows of a data source in column layout. Use a ListView control to edit, delete, and insert rows in a data source. Use a DataPager control to provide customized paging for a ListView control. Knowledge In general terms, describe the use of these templates when you’re using a ListView control: LayoutTemplate, ItemTemplate, AlternatingItemTemplate, EditItemTemplate, InsertItemTemplate, SelectedItemTemplate, GroupTemplate, and EmptyItemTemplate. In general terms, describe the use of a DataPager control. Explain what the before-action and after-action events of a ListView control are typically used for. 17 106762962 Chapter 17 How to use object data sources Objectives Applied Use object data sources to develop 3-layer ASP.NET database applications. Create a data access class that can be used with an object data source. Use business objects with object data sources. Use paging with object data sources. Knowledge In general terms, describe how 3-layer applications work in ASP.NET. Describe the two main benefits of using object data sources. Explain what reflection is and how it’s used with object data sources. Describe the way business objects are used with object data sources. 18 106762962 Chapter 18 How to secure a web site Objectives Applied If you’re using IIS 5.1 or 6.0, request and install a digital secure certificate or a trial certificate. If you’re using IIS 7, request and install a digital secure certificate, or create a selfsigned certificate and a binding for the HTTPS protocol. Develop a web site that contains one or more secure pages. Knowledge In general terms, explain how secure connections work. In general terms, explain how digital secure certificates work. Explain how the strength of a digital secure certificate affects its level of security. Describe the difference between a single root certificate and a chained root certificate. Describe the functions that are provided by IIS for working with digital certificates. 19 106762962 Chapter 19 How to authenticate and authorize users Objectives Applied Use the Web Site Administration Tool to enable forms-based authentication and to create and manage roles, users, and access rules. Use the Login, LoginStatus, and LoginName controls to provide the functionality required for a web site that contains restricted pages. Use the CreateUserWizard, PasswordRecovery, and ChangePassword controls to allow users to create and manage their own accounts. Use the LoginView control to determine the message that’s displayed depending on whether a user is logged in. Knowledge Describe how the three types of authentication work. Describe the purpose of roles, users, and access rules. Describe the basic purpose of the AspNetDb.mdf database. Describe the basic procedure for modifying a data provider. 20 106762962 Chapter 20 How to use email, custom error pages, and back-button control Objectives Applied Send email messages from your web applications including messages with multiple recipients, attachments, and HTML formatting. Display custom error pages for any ASP.NET exceptions or HTTP errors that occur while your web applications are running. Prevent the back-button problem from occurring in your applications. Knowledge Describe the use of MailMessage, MailAddress, SmtpClient, and Attachment objects as they relate to sending email messages from a web application. Describe three ways to catch the exceptions that are thrown by your ASP.NET applications. Describe how you can use the web.config file to handle specific types of HTTP errors. Describe the “back-button problem.” Describe two ways to handle the back-button problem. 21 106762962 Chapter 21 How to use AJAX Objectives Applied Use the ASP.NET AJAX server controls to develop simple ASP.NET AJAX applications. Knowledge Distinguish between a normal HTTP request and an AJAX HTTP request. In general terms, describe the ASP.NET AJAX client-side framework and the ASP.NET AJAX controls. Describe the use of these ASP.NET AJAX controls: ScriptManager, ScriptManagerProxy, UpdatePanel, UpdateProgress, and Timer. In general terms, describe how jQuery AJAX differs from ASP.NET AJAX. 22 106762962 Chapter 22 How to configure and deploy ASP.NET applications Objectives Applied Use the Web Site Administration Tool and the IIS Management Console to configure an ASP.NET application. Deploy an application by using either the Copy Web Site command or the Publish Web Site command. Knowledge Describe the three ways to deploy an ASP.NET application. Describe two advantages of precompiling a web site before deploying it. 23 106762962 Chapter 23 An introduction to WCF services Objectives Applied Code and test simple WCF services. Create a web site that hosts a WCF service library. Use WCF services in your web applications. Knowledge In general terms, explain how WCF services work. Describe the basic contents of the IService1.cs and Service1.cs files that are included by default in a WCF service library. Describe the use of the following attributes: ServiceContract, OperationContract, DataContract, and DataMember.