1 / 74

Developing Windows and Web Applications using Visual Studio.NET

Developing Windows and Web Applications using Visual Studio.NET. Drew Robson. Session 6: ASP.NET. The course ten sessions – Overview so far Overview of ASP.NET An ASP.NET Page Server Controls User Controls Validation Master Pages Themes & skins.

Télécharger la présentation

Developing Windows and Web Applications using Visual Studio.NET

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. Developing Windows and Web Applications using Visual Studio.NET Drew Robson

  2. Session 6: ASP.NET The course ten sessions – Overview so far Overview of ASP.NET An ASP.NET Page Server Controls User Controls Validation Master Pages Themes & skins

  3. The 10 SessionsFirst 5 – Done – Winforms • Overview of .NET, OOP and Visual Studio • Data in Forms • Usability - Rules to Better Windows Forms • Deployment of Windows Forms and Design Patterns • Web Services (WCF) and Threading

  4. The 10 SessionsNext 5 – To Do – Webforms • Overview of .NET Webforms TODAY • Data in Webforms • Usability and Reporting • Silverlight • MVC, jQuery and AJAX

  5. The web

  6. HTML • HyperTextMarkupLanguage • Describes a web page http://en.wikipedia.org/wiki/HTML <html> <head> <title>Hello HTML</title> </head> <body> <p>Hello World!</p> </body> </html>

  7. HTTP • Hypertext Transfer Protocol • Request – Response http://en.wikipedia.org/wiki/Http GET /index.html HTTP/1.1 Host: www.example.com HTTP/1.1 200 OK Date: Mon, 23 May 2005 22:38:34 GMT Server: Apache/1.3.3.7 (Unix) (Red-Hat/Linux) Last-Modified: Wed, 08 Jan 2003 23:11:55 GMT Content-Length: 438 Content-Type: text/html; charset=UTF-8

  8. How a web page is shown Your Computer Hosting Computer Internet The Internet Server Client

  9. Request / Response Request www.ssw.com.au The Internet Response Server HTML Client

  10. .NET Overview • IL = Intermediate Language • CLR = Runtime

  11. What Is ASP.NET? ASP.NET provides a complete environment for building, deploying, and running .NET Web applications. • Developer Productivity • Simplified page development model • Target any Web client (PC or mobile device) • Modular, well-factored, extensible architecture • Superior debugging and tracing support • Enhanced Performance, Scalability, and Reliability • Compiled, not interpreted • Rich caching support • Web farm scalable session state • Automatically detects and recovers from errors • Simple Deployment and Configuration • No need to bring down Web server • Deploy and upgrade running applications with XCOPY • XML configuration files

  12. Request / Response Request ASP.NET www.ssw.com.au The Internet Response Server HTML Client

  13. ASP.NET Page Request • User requests an application resource from the Web server. • IIS forwards the call to ASP.NET’s process • Application manager calls the Application domain & Processes the page.

  14. ASP.NET Page RequestMulti user

  15. Parse Generate Code-behindclassfile ASPX Engine Request Gen’dPageClassFile ASPX File Instantiate Request Page Class Response (HTML/js/dhtml/etc…) Instantiate, process and render ASP.NET Compilation

  16. 2 Types of Projects – 1 – Web Site Web Site • Don’t use this, here for compatibility only • File > New > Web Site • Each page is dynamically loaded into memory • Slow on first load after deployment • No need to recompile for code change

  17. 2 Types of Projects – 2 – Web Application Web Application - • Recommended • File > New > Projects, then Select Web Application • Compiles all pages into one DLL • Faster on first load after deployment • Must recompile whole site for code change • Not available in Default VS 2005, requires SP2

  18. Parse Generate Code-behindclassfile ASPX Engine Request Gen’dPageClassFile ASPX File Instantiate Request Page Class Response (HTML/js/dhtml/etc…) All pre compiled! ASP.NETCompilation Web Application

  19. The Page

  20. ASP.NET –Page/Web Form An ASP.NET Web page consists of two parts: • Visual elements, which include markup, server controls, and static text. • Programming logic for the page, which includes event handlers and other code.

  21. ASP.NET – Page/Web Form Things to Notice

  22. Things to Notice • Page Directive ASP.NET – Page/Web Form

  23. Things to Notice • Page Directive • Server side code ASP.NET – Page/Web Form

  24. Things to Notice • Page Directive • Server side code • Form ASP.NET – Page/Web Form

  25. Things to Notice • Page Directive • Server side code • Form • Normal HTML Structure ASP.NET – Page/Web Form

  26. Things to Notice • Page Directive • Server side code • Form • Normal HTML Structure • Server Controls ASP.NET – Page/Web Form

  27. ASP.NET – Page Code Model ASP.NET provides two models for managing the visual elements and code: • The Single-File Page Model <%@ Page Language="VB“> <script runat=“server”> … </script> • The Code-Behind Page Model <%@ Page Language="VB“ CodeFile="SamplePage.aspx.vb“ Inherits="SamplePage“ AutoEventWire="false" %>

  28. A Page's Life

  29. ASP.NET – Page Life Cycle Stages (SILVER-U) • Page request • Start • Page Initialization • Load • Validation • PostbackEvent handling • Rendering • Unload http://msdn.microsoft.com/en-us/library/ms178472.aspx

  30. ASP.NET – Page Life Cycle Stages (SILVER-U) 1) Page request • Occurs before the page life cycle begins. • When the page is requested by a user • ASP.NET determines whether the page needs to be parsed and compiled (therefore beginning the life of a page), or if a cached version of the page can be sent in response without running the page.

  31. ASP.NET – Page Life Cycle Stages (SILVER-U) 2) Start • Page properties set • Request and • Response • Determines whether the request is a postback or a new request and sets the IsPostBack property. • Sets the page's UICulture property

  32. ASP.NET – Page Life Cycle Stages (SILVER-U) 3) Page Initialization • Controls on the page are available • Each control's UniqueID property is set. • Themes are applied to the page. • If the current request is a postback, the postback data has not yet been loaded and control property values have not been restored to the values from view state.

  33. ASP.NET – Page Life Cycle Stages (SILVER-U) 4) Page Load • If the current request is a postback, control properties are loaded with information recovered from view state and control state.

  34. ASP.NET – Page Life Cycle Stages (SILVER-U) 5) Page Validation • The Validate method of all validator controls is called • Sets the IsValid property of • Individual validator controls • The page

  35. ASP.NET – Page Life Cycle Stages (SILVER-U) 6) Postback Event Handling • If the request is a postback, • Event handlers are called

  36. ASP.NET – Page Life Cycle Stages (SILVER-U) 7) PageRendering • Before rendering, view state is saved for the page and all controls. • During the rendering phase, the page calls the Render method for each control, providing a text writer that writes its output to the OutputStream of the page's Response property.

  37. ASP.NET – Page Life Cycle Stages (SILVER-U) 8) Page Unload • Unload is called after the page has been: • Fully rendered, • Sent to the client, and • Is ready to be discarded. • At this point, page properties such as Response and Request are unloaded and any cleanup is performed.

  38. ASP.NET – Page Life Cycle Stages (SILVER-U) • Page request • Start • Page Initialization • Load • Validation • PostbackEvent handling • Rendering • Unload http://msdn.microsoft.com/en-us/library/ms178472.aspx

  39. ASP.NET – Page Life Cycle Events • PreInit • Init • InitComplete • PreLoad • Load • Control events • LoadComplete • PreRender • SaveStateComplete • Render • Unload

  40. Postback & ViewState

  41. Client submits data back to the server E.g. Submission of a form Page Postback

  42. Page Viewstate Allows the state of objects (serializable) to be stored in a hidden field on the page ViewState is transported to the client and back to the server Is not stored on the server or any other external source. ViewState is used to retain the state of server-side objects between postbacks Server can see if values have changed

  43. Server controls

  44. ASP.NET – Server Controls Server controls are tags that are understood by the server. Syntax: <asp:control_name id="some_id" runat="server" /> Example: <asp:Button id="button1" Text="Click me!" runat="server" OnClick="submit" />

  45. Demo How to create a web application How to create a web form Designer Features Different Page Code models Postbacks Viewstate, Session State, Application State

  46. User controls

  47. ASP.NET User Controls A group of server controls that are created by the user. Encapsulates certain functionality Can be used on multiple pages E.g Address User control (in your lab) Contact User Control

  48. ASP.NET Configuration

  49. ASP.NET Configuration Web.Config Similar to app.config in windows Application-wide configuration Provide application settings In XML, so it’s easy to change

  50. Who is the Master?

More Related