Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are the differences between User Controls, Server Controls & Custom Controls?

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?
like image 353
IAmAN00B Avatar asked Jun 14 '09 23:06

IAmAN00B


2 Answers

  • 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.

like image 169
JoshBerke Avatar answered Oct 07 '22 00:10

JoshBerke


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

like image 41
Robert Harvey Avatar answered Oct 07 '22 01:10

Robert Harvey