Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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.


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.


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.


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