.NET framework offers multiple options for achieving the development tasks and it is always challenging to decide when to use what. The data repeater controls in .NET i.e. Repeater, User Control, Custom control, dropdown list etc offers functionality of repeating the data on pages and we would discuss about those controls and their usage.
Objective
To explore the different data repeater
controls in ASP.NET and understand when to use what.
Introduction
With the time progressing, .Net framework
has become very rich in terms of functionality it offers and also the readymade
controls which make the developers job a lot easy. I still remember the days of
ASP.NET 1.0 and 1.1 where one had develop many controls on their own or extend
the existing control to achieve their goals. Some of the examples are datagrid,
list etc for which we have now more rich controls like grid-view etc. But with
.Net framework offering multitudes of options, the onus has fallen on
developer/architects to choose the best option and this task is easier said
than done. One such instance would be the options for achieving display of
repeated data. Following are the options
· Repeater Control
· User Control
· Custom Control
· List controls
Let’s discuss about these options including
their base classes, facilities/features etcDescription
Name of the Control
|
Description
|
Inheritance, implements and features
|
Repeater Control
|
It is a basic container control that allows creating custom lists
from any data available to the page i.e. it allows custom
layout by repeating a specified template for each item displayed in the list.
|
· Inherits from System.Web.UI.Control and
part of System.Web.UI.WebControls
· For reusability one needs to
copy and paste the code snippet
· Needs lot of hand coding to
use
|
User Control
|
It is a composite control which acts just like webpage
and wherein one can add server controls, mark up, properties and methods.
|
· Inherits from System.Web.UI.TemplateControl and member of System.Web.UI.
· Intrinsically reusable
· Doesn’t provide templates by
default rather ITemplate needs to be implemented.
· Not so difficult to develop
and also easy to use
|
Custom Control
|
This essentially extends the specific
control whose functionality is not sufficient for the cause and requires
advanced knowledge to author.
|
· If the control is supposed to
render a user interface (UI) element or any other visible element on the client,
one should derive your control from System.Web.UI.WebControls.WebControl or a from class that derives from it. In case
when control is supposed to render an element that is not visible in the
client browser, such as a hidden element or a meta
element, one needs to derive custom control from System.Web.UI.Control.
Needs advanced knowledge to
author and available in toolbox
|
List Controls
|
Allows the user to select a single item
from a drop-down list. A list control is based on the
idea of a repeated control i.e. which needn’t be an individual control rather
it can also be a tree of controls with a common root.
|
· Inherits
from System.Web.UI.WebControls.ListControl
and member of ystem.Web.UI.WebControls
· Doesn’t provide templates by
default rather ITemplate needs to be implemented.
· Easiest to use for listing
|
Scenario
|
Choice
|
The records to be bounded have custom (layout) but fixed pattern and reusable --- limited
layout capabilities
|
Custom List control , ITemplate
classes
|
Page specific solution
|
Repeater or inline code
|
Different views of same content or changing
of templates at run time e.g. header, menus
|
User Control
|
Full control over layout and enhanced
functionality
|
Custom Control with templates
|
Summary & Conclusion
We explores the options for data repeater
controls in ASP.NET and also discussed about their base classes, features etc.
We explored couple of scenarios to drive to choice of such controls over each
other. Hope this discussion would help developer and architects to categorise
their requirements and settle for better choice of controls in turn to win over
the usual dilemma in software development as what to use and when.
HAPPY ARCHITECTING AND DESIGNING!!!
Reference
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.repeater.aspx