One of the aspects of ASP.NET that makes it so powerful is that it is object-oriented and makes object and component programming easy. As mentioned in previous sections, a C#Builder ASP.NET application consists of a Web Form and a code-behind file. For these to work together, there must be some relationship between these files. Additionally, there must be some relationship between the code in these files and the rest of the ASP.NET infrastructure. These relationships do exist via inheritance, as illustrated in Figure 11.6. Figure 11.6. ASP.NET Web page architecture.The Web Form, WebForm1.aspx, at the bottom of Figure 11.6 inherits the code-behind file, WebForm1.aspx.cs. The mechanism that makes this possible is the Inherits attribute of the Page directive, shown following: <%@ Page language="c#" Debug="true" Codebehind="WebForm1.aspx.cs" AutoEventWireup="false" Inherits="SimpleWebPage.WebForm1" %> In the Page directive, the code-behind file is named WebForm1.aspx.cs and is identified by the Codebehind attribute. The Inherits attribute identifies the fully qualified type of the class in the code-behind file. It is in the SimpleWebPage namespace, with a class name of WebForm1. Whenever a control is dragged from the Tool Palette and dropped onto the designer surface, a tag is added to the Web Form code. At the same time, a type declaration for that control is added to the WebForm1 class in the code-behind file. This way, both the Web Form and code-behind can access that control as a normal C# object. As illustrated in Figure 11.6, the WebForm1 class in the code-behind file inherits from the Page class. A snippet of the code is shown following: namespace SimpleWebPage { /// <summary> /// Summary description for WebForm1. /// </summary> public class WebForm1 : System.Web.UI.Page { The Page class contains functionality that enables the Web Form and code-behind file to access ASP.NET functionality. For instance, the Request object enables access to the caller's HTTP information sent when a request was made. Along the same lines, the Response object contains information that will be returned to the caller's browser. Table 11.3 identifies available properties of the Page class and what they are for.
|