【正文】
he following sample demonstrates how the asp:adrotator control can be used to dynamically display rotating ads on a page. Each server control is capable of exposing an object model containing properties, methods, and events. developers can use this object model to cleanly modify and interact with the page. Note, however, how much cleaner and easier the code is in this new servercontrolbased version. As we will see later in the tutorial, the page Framework also exposes a variety of pagelevel events that you can handle to write code to execute a specific time during the processing of the page. Examples of these events are Page_Load and Page_Render. The example below demonstrates a simple page with three server controls, a TextBox, Button, and a Label. Initially these controls just render their HTML form equivalents. However, when a value is typed in the TextBox and the Button is clicked on the client, the page posts back to the server and the page handles this click event in the code of the page, dynamically updating the Text property of the Label control. The page then rerenders to reflect the updated text. This simple example demonstrates the basic mechanics behind the server control model that has made one of the easiest Web programming models to learn and master. Note that in the preceding example the event handler for the Button was located between tags in the same page containing the server controls. calls this type of page programming codeinline, and it is very useful when you want to maintain your code and presentation logic in a single file. However, also supports another way to factor your code and presentation content, called the codebehind model. When using codebehind, the code for handling events is located in a physically separate file from the page that contains server controls and markup. This clear delineation between code and content is useful when you need to maintain these separately, such as when more than one person is involved in creating the application. It is often mon in group projects to have designers working on the UI portions of an application while developers work on the behavior or code. The codebehind model is wellsuited to that environment. introduces an improved runtime for codebehind pages that simplifies the connections between the page and code. In this new codebehind model, the page is declared as a partial class, which enables both the page and code files to be piled into a single class at runtime. The page code refers to the codebehind file in the CodeFile attribute of the % Page % directive, specifying the class name in the Inherits attribute. Note that members of the code behind class must be either public or protected (they cannot be private). The advantage of the simplified codebehind model over previous versions is that you do not need to maintain separate declarations of server control variables in the codebehind class. Using partial classes (new in ) allows the server control IDs of the ASPX page to be accessed directly in the codebehind file. This greatly simplifies the maintenance of codebehind pages. Although you can place code inside each page within your