What's the difference between Render and RenderControl in WebControl creation?

Michael Itzoe picture Michael Itzoe · Oct 31, 2009 · Viewed 10.8k times · Source

I've recently learned to write my own WebControls, but I'm still hazy on the difference between Render and RenderControl. I started out using Render, but at some point I started using RenderControl, which I now use exclusively. If I'm forming a bad habit I'd like to nip it in the bud now before I get set in my ways.

Answer

o.k.w picture o.k.w · Oct 31, 2009

Here's a good read: Render vs RenderControl

Excerpt from links:

The Render method enables the controller to render itself by writing HTML output to the response stream. This passes a reference to the HTMLTextWriter object, which can write directly to the response stream. This method should be used when you derive directly from control.

The RenderControl method is used by the page to render each individual control. It allows the consumer of your class to render it, and you can use it to render the child controls if you're using a composite control. Also, one thing to note is that this will not be invoked if the visibility property on the control is set to false.