ASP.NET Custom Server Controls: Breaking the Secrets of Rendering - Secrets of “RenderBeginTag” and “RenderContents”
(Page 4 of 5 )
There is something more we need to understand about “RenderBeginTag.” Internally within the ASP.NET framework, the method has been defined something like this (unless we override it):
Public virtual void RenderBeginTag(HtmlTextWriter Writer)
{
AddAttributestoRender(writer);
HtmlTextWriterTag tagKey = TagKey;
If(tagKey != HtmlTextWriterTag.Unknown)
Writer.RenderBeginTag(tagKey);
Else
Writer.RenderBeginTag(this.tagName);
}
The “RenderBeginTag” calls another method, the “AddAttributestoRender” method, to deal with all types of “attributes” related to only the opening tags. The “TagKey” corresponds to the default HTML tag corresponding to the web control. If we implement our own tags within the “RenderBegintag” method, we can simply forget about the “TagKey” issue. If you still want to know how to implement “TagKey“, the following is a sample (but generally not very much required):
Protected override HtmlTextWriterTag TagKey
{
Get
{
Return HtmlTextWriterTag.Input;
}
}
Now that we have learned about “RenderBeginTag,” let us proceed to “RenderContents.” Internally within the ASP.NET framework, “RenderContents” has been implemented something like this:
Protected virtual void RenderContents(HtmlTextWriter Writer)
{
Base.Render(Writer);
}
The statement “Base.Render(Writer)” must be issued at the bottom, if and only if you have some child controls to be rendered, exactly in the same hierarchy of this control’s lifecycle. This statement would indeed call the “Render” method of each and every child control which exists as part of this control recursively. If you don’t have any child controls for your control, you need not include the statement.
Next: What about the “AddAttributesToRender” method? >>
More ASP.NET Articles
More By Jagadish Chaterjee