What are User Controls and Custom controls?

 Posted by Biswarup90 on 11/23/2011 | Category: .NET Framework Interview questions | Views: 3321 | Points: 40

Custom controls are control build entirely in code. The pro is that you can put them in libraries, add an icon to the toolbox and other fine control.

User controls are more easy to do, and in general is a way to encapsulate things to simplify other pages or when you need to use the same markup in several pages.

Asked In: Many Interviews | Alert Moderator 

Comments or Responses

Posted by: Biswarup90 on: 11/23/2011 | Points: 10
There are two main categories of creatable Web controls. User controls are more simple to create, but custom controls are more simple to use. The extra effort that goes into creating custom controls pays off for the developer using the control at design time.

User controls are the natural evolution of include files, which are well known by old school ASP developers. If you're still using server-side include files in ASP.NET, it's time to leave them behind and dig into user controls, which are better in virtually every way. User controls are little more than a snippet of a Web page that can be dragged and dropped anywhere to duplicate bits of user interface and the associated functionality. (In fact, it's not difficult to convert an entire Web page into a user control.) They are object-oriented, so public properties can be added, as well as methods and events, to allow them to easily communicate with the page and other controls on the page.

User controls are saved with an ASCX file extension. Although they can be easily reused on any of the pages within the project in which they were created, there is no good way to reuse them in a different project. Another downside to user controls is that they only appear on the page at run time; at design time they appear on the page as an ugly gray box, making it difficult to envision how they'll appear to your users.

Login to post response

More Interview Questions by Biswarup90