From Text to Controls


Page developers and designers create ASP.NET pages in a declarative text format (as you can see in Listing 2-1) by using either a visual designer such as Visual Studio .NET or a simple source editor. A typical .aspx page contains static text, static markup tags (such as HTML elements), server controls, and optional server-side code represented by script tags with the runat ="server" attribute.

At run time, the page framework parses the text in the .aspx file and creates instances of server control classes that correspond to each tag that has a runat="server" attribute. In addition to creating specific server controls, the page framework creates a special control, LiteralControl , to represent each span of contiguous static text and markup present in the page. The instantiated controls are assembled into a control tree. For example, the control tree corresponding to the page you saw in the Listing 2-1 is shown in Figure 2-3.

Figure 2-3. The control tree created as a result of parsing the page shown in Listing 2-1

graphics/f02hn03.jpg

The control tree is a hierarchical arrangement of controls. The Page class, which derives indirectly from the System.Web.UI.Control class (shown in Figure 2-1), represents the .aspx file and is the root of the tree. Its children represent the contents of the .aspx file. Each control (other than the Page instance) has a reference to its parent in the hierarchy. At the same time, each control can act as a parent for other controls. The page framework allows the page developer and custom controls to perform standard operations on this control tree, such as adding and removing child controls and retrieving controls by either their identifier or their position in the tree.

Page processing is very closely tied to the control tree that results from the parsing process. The page framework processes each control in each processing phase it goes through, such as the initialization and rendering phases. The page framework processes the controls in a preordered fashion ”in other words, the parent is processed first, followed by its children. This processing scheme ensures that controls are processed in the order in which they appear in the .aspx file.



Developing Microsoft ASP. NET Server Controls and Components
Developing Microsoft ASP.NET Server Controls and Components (Pro-Developer)
ISBN: 0735615829
EAN: 2147483647
Year: 2005
Pages: 183

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net