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.
4 Answers
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.

- 21,012
- 5
- 52
- 81

- 25,490
- 6
- 66
- 63
Render is a protected method, meaning that only derived Classes can access it. It is called within the Event Lifecycle, and shouldn't be explicitly called in your code.
RenderControl is a public method that allows you to call the Render method when you want. You would use it in, say, a Custom Control where you store Controls in the ControlsCollection but want to Render them in their own cell in a table. For example:
writer.Write(""): foreach(Control ctl in Controls) { writer.Write("") ctl.RenderControl(writer); writer.Write(""); } writer.Write("");
You should always override Render, and not RenderControl, as it is called in the Event Lifecycle (as I have already said)
(from http://forums.asp.net/t/909220.aspx/1, sorry my answer is just a copy-and-paste from that, but I didn't see much point rewriting such a crystal clear explanation)
I still don't understand why MS didn't simply make Render() a public method. Why is a separate RenderControl() necessary? The reasoning for that is missing from all the answers given so far. The first person who can explain it gets a shiny upvote.

- 7,538
- 5
- 55
- 74
-
+1 for detailing some of the confusing bits about the system. Helped paint a fuller picture for me. – Paul d'Aoust Sep 21 '12 at 16:35
-
Looking at the answer by **o.k.w**, I see that one point to separate the two, is that `RenderControl` provides some automatic overhead (like it will not render if the visibility is set false), so that the maker of the control does only need to provide the HTML for the rendered control without having to worry about checking if it should be rendered or not. This could be dependent on control hiarchy, and not just the control's own visibility property. Remember that the `Render` override code writes directly to the stream - not calling som object code that can check this for you. – awe Jul 05 '18 at 06:43
RenderControl is used if there is an existing control that provides what you want so you can take advantage of how that is rendered.
Render is used if you need to take full control over how the html is rendered.
You can of course combine the two for the most optimal use of your programming time...
EDIT
For a better explanation on this, and excellent point to what to use when, see the answer from mhenry1384.

- 21,938
- 6
- 78
- 91
-
This answer doesn't really explain the difference. Note that we have "an existing control that provides what you want" in both cases - the control is the instance of the class. This is not clear. – jakubiszon Jul 04 '18 at 09:07
-
1@Jakub When I see this now 8 years after I wrote it, I totally agree with you. The answers from [**mhenry1384**](https://stackoverflow.com/a/9150131/109392) and [**o.k.w**](https://stackoverflow.com/a/1653098/109392) are much better. – awe Jul 05 '18 at 06:17
RenderControl is used for the page to render child controls. Render allows an individual control to render itself.