ASP.NET Custom Server Controls: Breaking the Secrets of Rendering - The Secret behind “Render” method of “WebControl” class
(Page 3 of 5 )
Until now we have seen the rendering available only at the“Control” class. Now let us break the secrets of the “WebControl” class. In my previous articles, I always used only the “render” method to emit the HTML (related to the control). There exists a few more alternative methods (of course most flexible as well) to deal with this. Let us now look into some of them.
The “render” method exists in every control. Internally within the ASP.NET framework, it has been defined something like this (unless we override it):
Protected override void Render(HtmlTextWriter Writer)
{
RenderBeginTag(Writer)
RenderContents(Writer)
RenderEndTag(Writer)
}
Now, if we don’t want to consider just “render,” then we can forget completely about it and work on the other three methods, namely “RenderBeginTag,” “RenderContents” and “RenderEndTag.” “RenderBeginTag” should be generally implemented with all the opening tags of the control (together with their attributes). “RenderContents” generally contains the information which is required to be displayed (even child control information) within the same control. Finally “RenderEndTag” should be implemented with all the closing tags which were opened in “RenderBeginTag.”
Do you think the other three methods, namely “RenderBeginTag”, “RenderContents” and “RenderEndTag” can be taken for granted, without having any pre-processing? You are wrong. Each of them (except “RenderEndTag”) still require their own implementations internally within the ASP.NET framework.
The next section deals with those methods in detail.
Next: Secrets of “RenderBeginTag” and “RenderContents” >>
More ASP.NET Articles
More By Jagadish Chaterjee