Summary


This chapter compared custom controls and user controls based on their characteristics. Table 6-1 provides recommendations for some of the common server control development scenarios.

Table 6-1. Recommendations for Server Control Development Scenarios

Scenario

Recommendation

Deciding Requirement

Commercial or redistributable package of controls ”for example, standard ASP.NET controls

Custom controls

Must be able to deploy precompiled binaries.

Data-bound controls ”for ­example, the DataGrid control

Custom controls

Need to generate content and layout dynamically based on the data source. The ability to use static content functionality of .ascx does not help. In addition, data-bound controls generally need to provide design-time functionality that is not available to user controls.

Templated controls ”for exam ­ple, the DataList control

Custom controls

Need the ability to specify the content for the control as a template in the page containing the control. The ability to use static content functionality of .ascx does not help in this scenario. Template editing features require an associated designer that isn't available to user controls.

Extended controls ”for example, a hypothetical HoverImage control that derives from the standard Image control

Custom controls

Need to add new functionality to an existing control or to modify its behavior while preserving the object model of the inherited control class.

Reusable HTML snippets ”for example, the SiteHeader and SiteFooter user controls described in Chapter 4

User controls

Need to reuse HTML snippets. These snippets are usually application specific and primarily contain static content or markup.

Composite controls ”for example, the RequiredTextField user control described in Chapter 4

User controls

Need to create a new control by compositing (combining) a predetermined set of controls in a fixed layout. Composite controls are very easily authored using the RAD authoring support available for .ascx files.

Fragment caching ”for example, the CachedUserControl sample from Chapter 4

User controls

Need to cache fragments of a page. A user control offers a convenient declarative mechanism for caching by using the OutputCache directive.

This chapter should serve as a guide that helps you choose between the two control-authoring models provided by ASP.NET. At a high level, custom controls are suited for the creation of general purpose, redistributable, and oftentimes commercial class libraries, while user controls are suited for the creation of reusable user interfaces scoped to a single application or project.



Developing Microsoft ASP. NET Server Controls and Components
Developing Microsoft ASP.NET Server Controls and Components (Pro-Developer)
ISBN: 0735615829
EAN: 2147483647
Year: 2005
Pages: 183

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net