RenderContents Using enumerations

Continuing with my discovery of server controls, I have come across few more goodies. As I mentioned in my earlier blog posting that there are two different ways of writing content when you override RenderContents method inside of a server control. Here is an example of two different approaches.

image

image

In the above screen shots, I am showing 2 different approaches. In the first approach, I am using the built in enumerations where as in the second approach I am manually typing in the html. Writing html using the first approach has lot of benefits. First it gives you strongly typed access to the html content. Secondly asp.net framework supports two kinds of rendering; Html 4.0 and html 3.2 standard. If you write your html using the predefined enumerations as shown in the first approach, you get of out of the box adaptive rendering behavior based on configure settings to spit out either html 4.0 html or html 3.2 html.  There are various ways and configuration that help asp.net runtime determine what kind of html standard to send to the user's browser.

HtmlTextWriter are objects available in asp.net that is responsible for generation the html output that gets sent to the browser. There are two kinds of HtmlTextWriter available. One is HtmlTextWriter and second one is called Html32TextWriter. When a request is received by the asp.net runtime, it inspects the tagwriter property inside the user agent string and determines what textwriter to use to render html content. You can configure this setting by changing the values defined inside browsercaps element inside of machine.config for each of the different browsers available in the market.

No Comments