I thought I had reasonable answers for this question at a recent interview, but I bombed it. :(
- What are the major differences between the three?
- If not obvious by the answer to the previous bullet, when would you choose one over the other?
I thought I had reasonable answers for this question at a recent interview, but I bombed it. :(
User Controls are controls built with a designer within a web project. They typically are only private to a web application (Although there are ways you can make them available to other projects).
Server Controls are controls that are also known as Web Controls. These are reusable controls that render their html without the aid of a designer, they are created in a seperate assembly from the web application, are appropiate for controls which will be used in many different web applications
Composite Controls are a sub type of Web Controls and are controls which are made up (composed) of other web controls.
I've never heard of a custom control to mean anything other then a control which is custom built by you or your team. And it could include user, web or composite controls.
A User Control is a partial web page, created in the same way as any other web page in ASP.NET, except that it has an .ASCX extension, and it can be embedded in your other ASPX pages.
User controls are registered with the web page in which they are used, like this:
<%@ Register TagPrefix="UC" TagName="TestControl" Src="test.ascx" %>
They are then declared in the web page they are to be used in, like this:
<UC:TestControl id="Test1" runat="server"/>
Custom controls are compiled code components that execute on the server, expose the object model, and render markup text, such as HTML or XML, as a normal Web Form or user control does. Custom controls are written in C# or VB, and are derived from the class
System.Web.UI.WebControls.WebControl
Server controls are controls that execute on the server and render markup to the browser. User controls and custom controls are both examples of server controls.
http://support.microsoft.com/kb/893667