Datasheet

Obviously, many components in this application can be written once and then reused. For instance, a set
of business rules that calculate a customer’s creditworthiness or calculate the discounts available on an
order shouldn’t be duplicated in all the places where an order can be made there’s just too much
danger that different versions of this code will get different answers. However, this code is implementing
business rules and should be put in an object that is accessed by the parts of the application that need that
processing.
There are a number of places in this application’s user interface where a standardized, reusable control
would be useful. Each page, for instance, should have the company logo and basic page information at
the top. ASP.NET’s master pages sound like a solution to this problem but the page information isn’t
exactly the same for every customer (the customer name is included in the page’s title bar, for instance).
A Web Part would allow you to build a standard title bar for the top of the page that a user could modify
to include their name as they want to be addressed and that would be automatically reloaded when that
user returns to the site. For this Web Part, very little code may be required just a set of properties that
allow the Web Part’s text and graphics to be updated may be sufficient. Figure 1-3 shows the title bars
from two different pages implemented through the same Web Part.
Figure 1-3
While the application allows many different ways to list books, the way each book is displayed should be
the same. By standardizing the way that book information is displayed, users can quickly figure out where
to find particular information (such as price, genre, and so on). To meet this need, a custom control that can
display a single book’s information would be very useful. Because most of the book information is kept in
a database, this Web Part could include the code to gather the information from the database either directly
or by interacting with a middle-tier object. All that the application would have to do is pass a book’s
unique identifier to the custom control and the control would take care of displaying the book’s data.
In fact, there’s probably a need for two controls: a detailed book control that would display all the
information on a book, and a summary book control that would display only basic information. Because
the detailed information control would use a wide variety of controls and formatting to display all the
information, it might be easiest to create it as a user control. Because the summary information control
requires fewer controls, it might be easily created as a custom control. Figure 1-4 shows examples of
these two Web Parts, with the detailed display above the summary display.
11
Creating Your Own Controls
05_57860x ch01.qxd 10/4/05 9:26 PM Page 11