Custom Control | User Control |
A loosely coupled control w.r.t code and UI | A tightly coupled control w.r.t code and UI |
Derives from Control | Derives from UserControl |
Defines UI in a ResourceDictionary | Defines UI as normal XAML |
UI is skinable | Child controls are skinable |
Has dynamic layout | Has static layout |
UI can be changed in different projects | UI is fixed and can't have different looks in different project |
Has full toolbox support, Jst drag n drop from toolbox | Can't be added to the toolbox, Jst drag n drop from sol’n explorer to page(aspx) |
Defines a single control | Defines a set of controls |
More flexible | Not very flexible like a Custom Control |
Reusability of control (extend functionality of existing control), Designed so that it can be used by more than one application | Reusability web page, Designed for single-application scenarios |
Compiled into dll | Not compiled into dll |
Creation is similar to the way Web Forms pages are created; well-suited for rapid application development (RAD) | Writing involves lots of code because there is no designer support |
Button
, CheckBox
, TextBox
etc., even a UserControl
is nothing but a Custom Control. You can easily load them inside a XAML page.Custom Controls are compiled into a DLL assembly and can be reused in multiple places very easily. You have total control over the code, thus gives you more flexibility to extend the behaviour. Once you build and add a reference of the custom control in your project, you can find it in the toolbox. Thus, you will be able to drag and drop the control in your Design view and start working with it very easily.
- When you have a rapid and fixed content in your UI, use UserControl.
- When you want to separate some basic functionality of your main view to some smaller pieces with reusability, use UserControl.
- When you want to use your control in different projects and each project may want to change the look, use CustomControl.
- When you want to implement some additional functionality for a control, create a CustomControl derived from the base control.
- When you want to apply themes to your controls, use CustomControl.
- When you want to add toolbox support for your control, so that your user will be able to do drag and drop to the designer, use CustomControl.
For user control:
<%@ Register TagPrefix="UC" TagName="TestControl" Src="test.ascx" %>
For custom control:
<%@ Register TagPrefix="CC " Namespace=" CustomServerControlsLib " Assembly="CustomServerControlsLib " %>
No comments:
Post a Comment