Summary Windows Forms II: Controls, Common Dialog Boxes, and Menus

236 Figure 5-35. A control with its Region property set to clip everything outside of the ellipse

5.7 Summary

The Windows Forms architecture is broad and deep. This chapter has presented everything you need to know to get started developing GUI desktop applications, but there is more power waiting for you after you assimilate whats here. Once you master the material in this chapter, you can write complex GUI applications. Youll also be able to tackle and understand additional types and functionality documented in the online .NET reference material. 237

Chapter 6. ASP.NET and Web Forms: Developing Browser-Based Applications

ASP.NET is a technology for developing dynamic web pages. It has evolved from Microsofts ASP technology, so experience with ASP transfers fairly well to ASP.NET. While I dont assume in this chapter that you have such experience, I do assume that you have at least a passing familiarity with HTML. ASP.NET works with Microsofts Internet Information Services IIS to dynamically create HTML content so it can be sent to a web browser. This technology supports all browsers, because ASP.NET runs entirely on the server and sends only HTML and, optionally, client-side JavaScript to the browser. With ASP.NET, web browsing works like this: 1. A user enters a web page address into a browser or links to the address from another web page. For example, ht t p: w w w .got dot net .com default .aspx . 2. The browser sends a request to the server in this case, www.gotdotnet.com, asking for the given web page in this case, default.aspx. 3. The server receives the request and attempts to fulfill it. How the server fills the request depends on the type of page requested, as indicated by the filename extension. Files with an .html or .htm extension are assumed to contain plain HTML text and are sent to the browser as is. Files with an .aspx extension are assumed to contain ASP.NET application code and are therefore compiled and executed. Executing the ASP.NET code usually results in generating HTML content and sending it to the browser. Note the following: o The browser is unaware that the content is dynamically generated. From the browsers perspective, the response could be from a static HTML file. o The .aspx file is compiled only once. The first time a browser requests the file, the ASP.NET framework compiles the file and stores the executable code on the server. Subsequent requests for the same page call directly into the executable code. The term Web Forms refers to a set of classes in the .NET Framework that provides support for building web applications. With the Visual Studio .NET IDEs built-in awareness of Web Forms, building web pages now has nearly the same drag-and-drop simplicity as building form-based desktop applications. In the ASP.NET framework, .aspx files can contain standard HTML tags which are sent as is to the browser, Web Forms tags which represent Web Forms classes and are interpreted by the ASP.NET runtime, rather than being sent to the browser, and code written in one of the .NET languages. ASP.NET pages are compiled. Even if an .aspx file contains only HTML, it is still compiled. This is quite interestingly done. During the compilation process, ASP.NET reads the .aspx file and creates a class capable of outputting the HTML found in the file. If the .aspx file contains any embedded Visual Basic .NET or other .NET language code, this code is compiled into the class. For example, if the .aspx file contains an embedded subroutine declaration, the subroutine becomes a method of the compiled class. At runtime, the compiled class is asked to generate its HTML, which is then sent to the browser. The compiled class that represents an ASP.NET web page is a .NET class. As such, it must inherit from some other class. By default, classes created by ASP.NET inherit from the Page class defined in the System.Web.UI namespace. This means the generated classes have all the capabilities that are built into the Page class. These capabilities are described later in this chapter, in Sect ion 6.2 . If desired, ASP.NET pages can specify a class from which to inherit, as long as the specified class itself ultimately inherits from the Page class. This is the foundation for separating a pages code from its HTML. Code is placed in a class that inherits from the Page class. The web page then specifies a directive indicating that its compiled class should derive from the custom class, rather than directly