1 / 68

Chapter 9

Chapter 9. Web Applications. Chapter Objectives - 1. Explain the functions of the server and the client in Web programming Create a Web Form and run it in a browser

Download Presentation

Chapter 9

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Chapter 9 Web Applications

  2. Chapter Objectives - 1 • Explain the functions of the server and the client in Web programming • Create a Web Form and run it in a browser • Describe the differences among the various types of Web controls and the relationship of Web controls to controls used on Windows forms • Understand the event structure required for Web programs • Design a Web Form using tables

  3. Chapter Objectives - 2 • Control the styles used on Web pages using cascading style sheets (CSS) • Create multiple pages in a Web application • Navigate using the HyperLink control and the Server object • Validate Web input using the validator controls • Use state management to preserve values in variables • Use AJAX to update a portion of a Web page • Define ASP.NET, XML, WSDL, and SOAP

  4. C# and Web Programming • Web Forms are used to create the user interface for Web applications • A Web Form displays as a document in a browser • You can create documents that display on mobile devices, such as cell phones and PDAs (using the Standard Edition and above)

  5. Client/Server Web Applications • Web applications require a server and a client • Server sends the Web Pages to the client • Client displays the Web Pages in a browser

  6. Web Servers • To develop Web applications • Use a remote Web server • Make your local machine a Web server • Visual Studio Web Server • Installs automatically with Visual Web Developer or Visual Studio • Simplifies development, testing, and debugging • Use IDE tools to transfer application to an IIS Web server after development to share with others • Internet Information Services (IIS)

  7. Web Clients • Browsers display pages written in a markup language such as HTML or XHTML • Pages may also contain program logic • Script • JavaScript, VBScript, JScript • Java applets • Programming for a network intranet • Users’ browser is known • Programming for the Internet • Test and check output on multiple browsers • Internet Explorer, Mozilla FireFox and Opera

  8. Web Pages • Web pages are stateless • The page does not store any information about its contents from one invocation to the next • Techniques for working around the stateless limitation • Storing cookies on the local machine • Sending state information to the server as part of the page's address, called the uniform resource locator (URL) • The server can send the state information back with the next version of the page

  9. ASP.NET • ASP.NET 3.5 is the latest Web programming technology from Microsoft • ASP.NET provides libraries, controls, and programming support for programs that: • Interact with the user • Maintain state • Render controls • Display data • Generate appropriate HTML • Write object-oriented, event-driven Web applications using C# and ASP.NET

  10. C# and ASP.NET • Each Web Form has two distinct pieces • HTML and instructions needed to render the page • C# code • A Web Form generates two files: • .aspx extension for the HTML • .aspx.cs extension for the C# code • Holds the logic to respond to events • Called the "code behind" file • C# code is not compiled into an .exe file, it is compiled into a dynamic link library (dll) file

  11. Types of Web Sites • Web applications are referred to as Websites in VS 2008 • Four types of Web sites • File System • Local IIS • FTP site • Remote site

  12. File System Web Sites • Store Web pages and associated files in any folder on the local computer or on the network • Does not expose the computer to security vulnerabilities • Does not require administrative rights to create and debug a Web project • Runs on Home Edition of Vista or XP

  13. IIS Web Sites • IIS on a local computer hosts a Web server that must be secured • Requires administrative rights on the computer to create IIS Web projects • By default files are stored in C:\inetpub\wwwroot folder • A virtual IIS directory can be created to store a Web site

  14. Remote Sites and FTP Sites • Administrative rights on the host computer must be granted to do development on a remote Web server • FTP cannot be used to create a new Web site • A previously created FTP Web site can be opened in Visual Studio

  15. Creating a Web Site • Select New Web Site from the File menu • In the New Web Site dialog box, select the template, location, and language • Give the Web site a name by appendingthe name tothe location

  16. Web Page Files • A new Web site automatically contains one Web page, Default.aspx • Visual representation of the page (HTML tags) • A second file, Default.aspx.cs, holds the C# code for the page • ASP.NET has a second model for Web applications—single-file model • Stores all HTML, control definitions, and code in one single file • The textbook teaches the code-separation model that uses two separate files

  17. Web Forms in the Visual Studio IDE • Differences between a Web application and a Windows Forms application • Web Form (page or document) not a Windows Form • Toolbar • List of files in the Solution Explorer • Toolbox has different controls • Properties and events different than controls that have a Windows counterpart • Views available in the IDE are Design, Source (HTML or ASP.NET) or a Split window

  18. Viewing the HTML Code • Three tabs at bottom of Web Form • Design • Split • Splits the Document window horizontally to see both the design and source • Source • Static HTML code

  19. Controls - 1 • Several types of controls available for Web Forms • Standard (ASP.NET server controls)—Richest and most powerful controls provided by ASP.NET and .NET framework • Data—Display database data • Validation—Validate user input before it is sent to server • Navigation—Includes the Menu control • Login—Login controls and wizards • WebParts—Change the appearance and behavior of the interface from the browser

  20. Controls - 2 • AJAX Extensions – Provide for faster Web page loading and richer interfaces • HTML – Standard elements that operate only on the client • HTML controls pass to and from the server as static text • Others – Depending on version of VS, other sections may be available (i.e. Reporting)

  21. Controls - 3 • In Design view, client-side HTML controls and ASP server controls are different • Popup DataTips identify the type of control and its ID (Name)

  22. Event Handling • Write C# code for events of Web controls in the same way as for Windows controls • Events may occur on either the client or server • The process of capturing an event, sending it to the server, and executing the required methods is all done automatically • Events of Web Forms and controls are different than for Windows Forms • Examples • Page.Load versus Form.Load • Button control has much shorter list of events for a Web Form versus a Windows From

  23. Files • Web application files differ greatly from a Windows application • aspx file • Holds specifications for the user interface used by the server to render pages • aspx.cs file • Code-behind file for the aspx file

  24. Debugging • The IDE does not automatically generate the code necessary for debugging a Web application • Run without Debugging • Ctrl + F5 or Debug/Start without debugging

  25. Run with Debugging • If you try to run with debugging (F5), a message box gives the choice to run without debugging or add the debugging code to the Web.config file • Add the following line of code to the Web.config file to run with debugging <compilation debug = “true” /> • Set breakpoints, single step execution, and display the contents of variables and properties at debugging time • Always remove debugging support before deploying an application • Debugging code slows an application considerably

  26. Testing in Other Browsers • To test in another browser, in the Solution Explorer: • Right-click on the project name • Select Browse With • Select from browsers installed on the computer

  27. Laying Out Web Forms • Factors that will affect the layout of page • Browsers • Screen sizes • Screen resolutions • ASP.NET generates appropriate HTML to render the page in various browsers but cannot be aware of the screen size, resolution, or window size on the target machine

  28. Using Tables for Layout • HTML tables contain rows and columns and allow control over placement of elements on a Web page • Add controls and text to the table cells to align the columns • A table is an HTML control, which requires no server-side programming

  29. Placing Controls orText in a Table - 1 • Add controls to any table cell or type text in a cell during design time • To refer to the text in a cell at run time, add a label and give it an ID or type text directly into the cell • Merge cells to allow room for a title or a larger image

  30. Placing Controls orText in a Table - 2 • Table borders show at design time but not at run time

  31. Absolute Positioning • Places controls in a specific X and Y position • Controls may not show up if user has set browser window to small size • Controls may overlap if the user has selected a large font size for the browser window • Controls can be dragged using the white tab at the top of a selected control • Controls remain in the same position relative to the Web page

  32. Including Images on Web Pages - 1 • Use the Image control to add graphics to a Web page • Concept is similar to the PictureBox on Windows Forms, but the graphic file is connected differently due to the nature of Web applications • Each Image control has an ImageUrl property that specifies the location of the graphic file • Best to first copy the graphic into the Web site folder • Add an Image control to a cell in a table or directly on a Web page

  33. Including Images on Web Pages - 2 • Web page table has three rows and three columns • Image and company title are in first row, textbox is in second row, hyperlink is in last row

  34. Cascading Style Sheets • New tools for using styles in Web applications are called Expression Web • Expands, enhances and simplifies using cascading style sheets (CSS) • Use CSS to create, modify and apply styles to single elements on a page, an entire page, all pages, or all applications of an organization

  35. Using Styles - 1 • Styles are rules that specify page layout, position, font, color, alignment, margins, borders, background and bullet and numbering formats • Create and apply new styles within a page • Attach an external .css file to apply styles • Save styles to an external .css file for use on other pages or Web sites

  36. Using Styles - 2 • Styles can be defined in several locations • Web page – inline style • For elements that appear only once on a page • style section – page style • For elements that may be used in more than one location on a page • external style sheet - .css file • For elements that may appear on more than one page or in multiple Web sites

  37. Using Styles - 3 • “Cascading” refers to the order of precedence of the style rules • For example • Style sheet (global) sets font, color, size, alignment • Local (page-defined) style for the color and size takes precedence (font and alignment still in effect from style sheet) • Inline (more local) style for the size takes precedence over local and style sheet (color from local and font and alignment from style sheet remain)

  38. Types of Styles - 1 • Several new tools are available to define, apply, modify and change the location of styles • Apply Styles window • Manage Styles window • Use the icons in the CSS Style Types table to identify the various types of styles

  39. Types of Styles - 2

  40. New Style Tools • New windows to define, apply and manage styles • CSS Properties • Manage Styles • Apply Styles • New Style Application toolbar appears in the default layout of the IDE

  41. New Style Windows andStyle Application Toolbar

  42. The Style Application Toolbar • Select Manual or Auto style application • Auto allows software to determine where to place CSS code • Manual allows choice of location of the styles using the Target Rule drop-down list • New Inline Style places style code into HTML code • Apply New Style allows creation of a new style in a new or existing .css file

  43. Defining Styles • Define a new style in the New Style dialog box • Choose the category and make settings • For example • Font • Block • Text-align, text-indent, vertical align • List • Bullet and numbering attributes • Table • Borders and spacing

  44. Managing Styles • In the Manage Styles Window, preview each style • Drag styles from one category to another to change the location of the style definition • A style created in the current page can be moved to a .css file to allow its use in other pages • In the CSS Properties window see the settings for a given style

  45. Applying Styles • Apply styles from several locations • Apply Styles window • Select the element on the page and click the desired style • Manage Styles window • Select the element on the page, right-click the desired style name and select Apply Style from the context menu • New Style dialog box • Check the box for Apply new style to document selection

  46. Modifying Styles • Change attributes of a style from the Apply Styles or Manage Styles window • Right-click on style name, select Modify Style from the context menu • Modify style attributes in the CSS Properties window

  47. Navigating Web Pages • ASP.NET provides several techniques to navigate from one Web page to another • Easiest form of navigation is to use a HyperLink control

  48. Using Hyperlinks • Add a HyperLink control to allow the user to navigate to another page or another site • Set properties of the HyperLink control • Text—Text to display for the user • NavigateUrl—Specify the URL to which to navigate • For another Web site, type the Web address (URL) • For another page in the application, use the Select URL dialog box and select the page from a list

  49. Adding a Second Web Page • Add a new form to the project • Add controls to the new page • Add a HyperLink to the Main Page • Set the Start Page • Run the application, test the links

  50. Transferring Pages in Code • At times a hyperlink cannot be used because some other action in code needs to be performed prior to the transfer • Transfer to another page in code • Use the Server.Transfer method Server.Transfer (“Offer.aspx”);

More Related