Article

Beginning ASP.NET Using VB.NET - Chapter 14: ASP.NET Server Controls

Page: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 Next

Rich Controls

Rich controls are controls are compound in nature, and provide extended functionality. In other words, these controls are typically combinations of two or more intrinsic controls that provide similar, but distinct functionality in one single control. Another distinguishing trait of these controls is that they don't have any direct correlation to any HTML controls, although they do in fact render to HTML when displayed in the client browser.

awroxtbl24b.png

awroxtbl25.png

The nice thing about this family of "Rich Controls" is that they are just as easy to use as the other ASP.NET server controls. They may boast more features and properties, but the basic way to define them and interact with them programmatically is exactly the same as all ASP.NET server controls. We haven't seen much of these yet, so let's look at a couple to see how they're used (to find out what properties any other controls have, consult the documentation).

Calendar

One of the simplest and most practical uses for this control is to allow a user to select a particular date. It's even possible, via the SelectionMode property, to configure the control to allow the user to select a range of dates. The Calendar control has many properties, and we'll list a few here, that are of particular interest:

<asp:Calendar id="Calendar1" runat="server"            
 FirstDayOfWeek="Default|Monday|Tuesday|Wednesday|            
 Thursday|Friday|Saturday|Sunday"

Notable here is the FirstDayOfWeek property -- this enables you to choose which day of the week your calendar starts from, and we will use this property in the example at the end of this chapter. Some calendars default to Sunday as the first day of the week -- for business purposes, however, it's typically more practical to view the week starting from Monday. A nice feature!

 SelectionMode="None|Day|DayWeek|DayWeekMonth"

By default, the Calendar control's SelectionMode defaults to Day. This is useful when you want your user to select a single day. You can select multiple days by setting the SelectionMode property to either DayWeek, however, which will allow you to select a single day or an entire week, or DayWeekMonth, which will allow you to select a single day, an entire week, or the entire month:

 SelectMonthText="HTML text"            
 SelectWeekText="HTML text"

The Calendar control's SelectMonthText and SelectWeekText allow you to customize the HTML -- use these properties if you're really going for a customized look.

You need not define all of the properties of the ASP.NET Calendar control to display the control. In fact, the following declaration will create an ASP.NET Calendar server control that looks and displays, depending on your tastes and needs, very nicely:

<asp:Calendar id="MyCalendarControl" runat="server" />

When delivered to the client browser, the result is an HTML calendar display that provides links which, when defined, enable you to navigate through the various days, months and years. Try it for yourself:

14_26_1.jpg

Have a look at the HTML that your ASP.NET produced to create this page -- over 100 lines of code, consisting of HTML and JavaScript, were generated to produce this and you wrote only a single line!

The ASP.NET Calendar control is extremely feature-rich. Refer to the ASP.NET documentation for complete details on this control.

If you liked this article, share the love:
Print-Friendly Version Suggest an Article

Sponsored Links