Chapter 8. Rendering


In user interface programming, the term rendering generally refers to the process of drawing or painting on a screen. However, in the case of server controls, rendering refers to the process of writing markup text (such as HTML, XML, and WML) to the HTTP response stream. The server sends the generated markup text to the requesting client, such as a Web browser, where it is finally transformed into its visual representation.

You have already seen some examples of rendering a control in Chapter 5, "Developing a Simple Custom Control," and Chapter 7, "Simple Properties and View State." In Chapter 5, we implemented rendering in the PrimeGenerator and StyledPrimeGenerator controls, and in Chapter 7, in the PageTracker control. In this chapter, we'll take a more detailed look at the rendering functionality that is available to a control. We'll examine the rendering methods provided by the base control classes, describe the HtmlTextWriter class that encapsulates the HTTP response stream, and look at the various utility classes that ASP.NET provides for rendering. We'll also examine the ASP.NET mechanism that enables server controls to automatically render markup text that matches the capabilities of the requesting browser. Server controls can automatically generate HTML 4.0 for uplevel Web browsers and HTML 3.2 for downlevel browsers.

Note that a control can render textual content only. You can render other response types such as images by implementing custom HTTP handlers, which are described in Chapter 19, "HTTP Handlers." An HTTP handler can generate any content type permitted by the HTTP protocol.

If you are migrating to ASP.NET from traditional Active Server Pages programming and are accustomed to invoking Response.Write to render page output, we must caution you against invoking Page.Response.Write from your control. Although this method will write to the HTTP response stream, the rendered content might appear before or after the page renders its control tree. The rendered content will not appear in the location where a page developer expects it to appear, based on the position of your control in the page hierarchy. In addition, when you invoke Page.Response.Write from a control, you break the encapsulation provided by the page framework. Therefore, to implement rendering functionality in your control, you should override one of the rendering methods provided by the base Control and WebControl classes, as we'll describe in this chapter.



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