
ASP.NET Page and Control Rendering
Default Rendering
In the default rendering of ASP.NET Web page, an instance of the HtmlTextWriter class is created and the RenderControl method is called recursively by using the parameter that is set to the instance of the HtmlTextWriter class. Each control in the page control hierarchy appends its markup to the end of the HtmlTextWriter object. The content of the resulting HtmlTextWriter is what is rendered to the resulting browser.
When rendering HTML 3.2 content to clients, ASP.NET automatically uses the Html32TextWriter class. To determine the type of TextWriter object to use, the ASP.NET page framework queries the TagWriter property of the Browser object.
By default, when you are working with browsers that support HTML 4.0 or later, ASP.NET pages and controls render markup that complies with the XHTML 1.0 Transitional standard. To specify whether ASP.NET renders markup that complies with XHTML standards, configure the xhtmlConformance Element (ASP.NET Settings Schema) in the Web.config file for your application. For more information about ASP.NET and XHTML, see ASP.NET and XHTML. For more information about the page life cycle, see ASP.NET Page Life Cycle Overview.
Using a Custom TextWriter Object
By default, ASP.NET uses the appropriate TextWriter object for the requesting device. When you need more control over the TextWriter, you can use an existing class that inherits from the HtmlTextWriter class or you can create a custom text writer.
The XhtmlTextWriter and ChtmlTextWriter classes are two classes in the ASP.NET page framework that inherit from the HtmlTextWriter and Html32TextWriter classes, respectively. The XhtmlTextWriter and ChtmlTextWriter classes provide additional adaptive rendering capabilities. For example:
The XhtmlTextWriter class is useful for rendering XHTML markup to mobile devices and provides methods for customizing attributes of the rendered XHTML elements.
The ChtmlTextWriter class is useful for rendering cHTML or compact HTML to devices with limited memory and CPU power, together with small display screens, limited formatting capabilities, and a limited number of input options, such as a cellular telephone touch pad.
If you create a custom text writer or if you want to specify a particular text writer to render output for a specific device, you must map the text writer to the device that is using the markupTextWriterType attribute of the controlAdapters element in a .browser file for the application.
Device Filtering
Device filtering lets you declaratively customize the output rendering aspects of a Web server control property. You can apply filtering to control properties, custom attributes, and templates. You can also use device filtering on some attributes for the @ Page and @ Control directives. If multiple device filters are specified for a property or an attribute, the most specific filter takes precedence.
Device filter definitions that are used to filter output are based on the definition of browser types, as defined in your application. The default browser definition files are in the %SystemRoot%\Microsoft.NET\Framework\versionNumber\CONFIG\Browsers directory. Browser definition files that are specified in the App_Browsers folder for the application are merged with the default definition files.
For more information about device filtering, see ASP.NET Device Filtering Overview. For more information about the .browser file format, see Browser Definition File Schema (browsers Element).