Difference Between usercontrol and custom control in .net

Let us see differences
User control
1) Reusability web page
2) We can’t add to toolbox
3) Just drag and drop from solution explorer to page (aspx)
4) U can register user control to. Aspx page by Register tag
5) A separate copy of the control is required in each application
6) Good for static layout
7) Easier to create
8)Not complied into DLL
9) Here page (user page) can be converted as control then
We can use as control in aspx
Custom controls
1) Reusability of control (or extend functionalities of existing control)
2) We can add toolbox
3) Just drag and drop from toolbox
4) U can register user control to. Aspx page by Register tag
5) A single copy of the control is required in each application
6) Good for dynamics layout
7) Hard to create
8) Compiled in to dll



........................................................................................................................................................


see If none of the existing ASP.NET server controls meet the specific requirements of your applications, you can create either a Web user control or a Web custom control that encapsulates the functionality you need. The controls are reusable.
The main difference between the two controls lies in ease of creation vs. ease of use at design time.
Web user control :
1. Web user controls are easy to make, but they can be less convenient to use.
2. Web user controls are compiled dynamically at run time they cannot be added to the Toolbox
3. 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
4. If your control has a lot of static layout, a user control might make sense
web custom control :
1. Web custom controls are compiled code, which makes them easier to use but more difficult to create.
2. Once you have created the control, however, 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 makes maintenance easier

..................................................................................................................................................................................

User controls are used for reusing existing user interface elements and code, but are not useful for developing reusable components for multiple web applications.

Custom server control can be plugged in to multiple web applications and is created as a class that derives from either the Control or WebControl class of the System.Web.UI namespace. They are available to you just like built-in server controls that come with ASP.NET.

There are two types of custom server controls:

Rendered controls

Rendered controls consists of custom rendering of the text, tags etc combined with the rendered output of parent classes also. These controls override the Render method of the control they derived from. This method is called automatically by the page containing the control when it's displayed.

Composite controls

Composite controls are composed of existing controls whose rendered output forms the UI of the custom control. Compositional controls create their constituent controls by overriding the CreateChildControls method of the parent control.





.........................................................................................................................................................................................




User control

1.Compiled at runtime
2.HTML design (Visual design possible)
3.ASP.Net page model with code behind
4.Needs ASP.NET .aspx page to exist (can be used)
5.No design time interface
(Only a box representing the user control is available on an .aspx page)
6.Cannot be added to the ToolBox


Custom Server Control

1.Precompiled
2.No visual design. HTML needs to be declared programmatically
3.Component model
4.can be used in .aspx pages, user controls or other custom server controls.
5.Has design-time and run-time interface
6. Can be added to the ToolBox (using drag and drop)

First, a custom server control is precompiled, which gives it component-like behavior. If we designed correctly, it looks, acts and feels just like a nASP.NET built-in server control such as Text Box or label control.

A user control is compiled at run time. When the compiler finds the register directive in an .aspx page that points to a user control, it compiles the control before it inserts its content into the .aspx page.

Second main difference is that when using user controls, you hav ethe ability to create HTML in a designer. WE don’t hav ethe option with the Custom server control.

Note:

User controls are best when we create reusable user interface components for one specific application. Custom server controls are best for small and distinctive user interface options that can be used across many applications.

0 comments:

Post a Comment