What is the difference between UserControl, WebControl, RenderedControl and CompositeControl?

asp.net

asp.net Problem Overview


What is the difference, what is the official terms, are any terms obsolete in ASP.NET 3.5?

asp.net Solutions


Solution 1 - asp.net

UserControl: A custom control, ending in .ascx, that is composed of other web controls. Its almost like a small version of an aspx webpage. It consists of a UI (the ascx) and codebehind. Cannot be reused in other projects by referencing a DLL.

WebControl: A control hosted on a webpage or in a UserControl. It consists of one or more classes, working in tandem, and is hosted on an aspx page or in a UserControl. WebControls don't have a UI "page" and must render their content directly. They can be reused in other applications by referencing their DLLs.

RenderedControl: Does not exist. May be synonymous to WebControl. Might indicate the control is written directly to the HttpResponse rather than rendered to an aspx page.

CompositeControl: Inbetween UserControls and WebControls. They code like UserControls, as they are composed of other controls. There is not any graphical UI for control compositing, and support for UI editing of CompositeControls must be coded by the control designer. Compositing is done in the codebehind. CompositeControls can be reused in other projects like WebControls.

Solution 2 - asp.net

You've forgotten the ServerControl.

In my understanding it is like that:

  • There are only two different kind of controls: UserControl and ServerControl
  • CompositeControls are kind of "advanced" UserControls. Find some more info on Scott Guthries Blog.
  • All of them are WebControls (because they are all derived from System.Web.UI.Control)
  • They are all rendered in any way so i would like to see them all as rendered controls.

From MSDN:

> User Control

> In ASP.NET: A server > control that is authored declaratively > using the same syntax as an ASP.NET > page and is saved as a text file with > an .ascx extension. User controls > allow page functionality to be > partitioned and reused. Upon first > request, the page framework parses a > user control into a class that derives > from System.Web.UI.UserControl and > compiles that class into an assembly, > which it reuses on subsequent > requests. User controls are easy to > develop due to their page-style > authoring and deployment without prior > compilation.

> Server control

> A server-side component > that encapsulates user interface and > related functionality. An ASP.NET > server control derives directly or > indirectly from the > System.Web.UI.Control class. The > superset of ASP.NET server controls > includes Web server controls, HTML > server controls, and ASP.NET mobile > controls. The page syntax for an > ASP.NET server control includes a > runat="server" attribute on the > control's tag. See also: HTML server > control, validation server controls, > Web server control.

Solution 3 - asp.net

Like Web Forms, user controls can be created in the visual designer or they can be written with code separate from the HTML. They can also support execution events. However, since Web user controls are compiled dynamically at run time they cannot be added to the Toolbox and they are represented by a simple placeholder when added to a page.

This makes Web user controls harder to use if you are accustomed to full Visual Studio .NET design-time support, including the Properties window and Design view previews. Also the only way to share the user control between applications is to put a separate copy in each application, which takes more maintenance if you make changes to the control.

Web custom controls are compiled code, which makes them easier to use but more difficult to create. Web custom controls must be authored in code. Once you have created the control you can add it to the Toolbox and display it in a visual designer with full Properties window support and all the other design-time features of ASP.NET server controls. In addition you can install a single copy of the Web custom control in the global assembly cache and share it between applications, which make maintenance easier.

Solution 4 - asp.net

Contrary to Will's response, it is possible to reuse UserControls in other projects by referencing a web deployment project.

Solution 5 - asp.net

Since I don't have enough reputation yet to comment, I'll add this as an answer, but it refers to Will's answer above.

From the link you included:

> Composite controls are the right tool to architect complex components in which multiple child controls are aggregated and interact among themselves and with the outside world. Rendered controls are just right for read-only aggregation of controls in which the output doesn't include interactive elements such as drop-down or text boxes.

I believe the documentation is refering to UserControls that have been created by overriding the Render method as Rendered Controls. Thus, it is not a separate type as the question implies, but a way of implementing a UserControl; a pattern.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionThomas JespersenView Question on Stackoverflow
Solution 1 - asp.netuser1228View Answer on Stackoverflow
Solution 2 - asp.netJRoppertView Answer on Stackoverflow
Solution 3 - asp.netGovardhanView Answer on Stackoverflow
Solution 4 - asp.netGuillaume CRView Answer on Stackoverflow
Solution 5 - asp.netDonView Answer on Stackoverflow