On the eve of the official release of .NET 2.0, developers around the world were anxiously waiting and priming their PCs for a speedy download from MSDN. And who could blame them? Microsoft's .NET development platform has been a hit with the developer community ever since the first betas came out years ago.
Upon loading Visual Studio .NET 2.0 for the first time, many of us were like kids in a candy store. So much to play with and so little time! Microsoft has really hit a home run with the suite of new controls they've added to the toolkit, which are bound to make your life a lot easier. So, without teasing you too much further, here's a rundown of the new controls you now have at your disposal with ASP.NET 2.0.
MultiView Control
The MultiView control is essentially a container class for another control, which is new in .NET 2.0 - the View control. The View control is itself a container class for other controls. Only one View control from the MultiView is viewable at one time. You can use the MultiView's SetActiveView method or ActiveViewIndex property to specify which View will be visible at a given time.
The MultiView control is a great way to facilitate jumping between edit and read-only modes of database records. It also has some great built-in functionality to assist in creating a wizard look and feel. By adding a Button, LinkButton, or ImageButton to each View in the MultiView and setting the CommandName and CommandArgument values, the MultiView will automatically navigate between Views as directed. Table 1 shows a simple view of those values.
Wizard Control
The Wizard control expands on the premise of the MultiView and creates an extremely powerful WYSIWYG editor for creating a classic wizard design. The screenshot of the Wizard control in Figure 1 is actually taken from design view rather than at run time and gives you a feel for the rich visual editing power of the Wizard control.
The Wizard control contains a Collection of WizardStep objects that are added to the Wizard in the order in which you wish them to appear. Next, Previous, and Finish buttons are automatically added to each WizardStep to allow for navigation between steps.
ImageMap Control
The new ImageMap control lets you easily create images with clickable hot spots in a straightforward and simple manner. The control itself is similar to the standard Image control with the ImageUrl property containing the URL of the image displayed. However the ImageMap adds a few new properties:
HiddenField Control
The HiddenField control allows you to store data in a hidden field on the rendered HTML. Typically you'd use view state, session state, or cookies to do that, but if you can't, then this is an alternative. You can modify the data stored with the Value property. You can also capture client-side changes to the data via a ValueChanged event.
FileUpload Control
The FileUpload control is simply a replacement for the HTML version of the control. The .NET control runs in a very similar manner and has a HasFile property that indicates whether a file was selected in the control. You then have access to methods and properties such as SaveAs (saves the file to the server), FileBytes (size of the file), FileContent (gets a Stream of the file contents), and PostedFile (gets the HttpPostedFile object for the file itself) to manipulate the uploaded file as needed.
Substitution Control
The Substitution control provides you with a way to display dynamic data on a page while the rest of the data on that page may be pulled from cache. While the OutputCache directive may indicate that your page is being pulled from cache, data connected to a Substitution control will always be fresh.
SiteMapPath Control
The SiteMapPath control gives you an easy way to create customizable breadcrumbs for your entire site. You simple create a site map XML file such as the one shown in Listing 1. The SiteMapPath control will then read the XML file and based on the path of the current page, it will create the breadcrumb dynamically.
MenuControl
The Menu control is a great way to add customizable pop-out menus to a Web site. The control hosts a Collection of MenuItem objects, which are customizable with images or a variety of styles. You specify a NavigateUrl property for each MenuItem object in order to allow for easy navigation.
TreeView Control
The TreeView is a flexible and powerful tree control that can be data bound to a data source. The TreeView contains a Collection of TreeNode objects that can be customized with images, NavigateUrls, checkboxes, tool tips, different select actions (select, expand, select and expand), etc.
Data Source Controls
Data binding has been revamped in .NET 2.0. The addition of several new controls that encapsulate the functionality from the Connection, Command, and DataAdapter objects in .NET 1.x make data binding in .NET 2.0 easier than it has ever been with little or no code required to bind controls to complex data queries. The SqlDataSource pulls data from SQL Server, the AccessDataSource pulls from Access databases, and the XMLDataSource can pull from XML sources.
The ObjectDataSource control is added to allow you to pull data from any type of object. This will be useful when manipulating or representing the data in code before binding it to a control.
Nearly all data manipulations can now be handled in these objects. They can handle selecting, inserting, updating, deleting, sorting, filtering, paging, etc. The 1.x controls are still there for backward compatibility, but the new controls give you a much cleaner and equally powerful solution to data-binding problems.
Login Controls
.NET 2.0 comes packed with a full suite of controls aimed at assisting in the creation and maintenance of login security for your Web application. With the tools now available it is possible to create a robust and customized authentication system with no coding at all.
The controls focus on the concept of .NET memberships. Memberships provide a built-in way to validate and store user credentials. Memberships can be stored in SQL Server, Active Directory, or other sources as needed. .NET 2.0 also provides a slick Web site administration tool (shown in Figure 2) that you can use to visually modify security and performance settings for your Web site including, .NET memberships. A brief overview of the login controls used to handle these memberships is listed here:
The GridView offers the same easy data binding to the new data source controls listed above, but in addition to that it offers fully functional sorting and paging with no extra code. Simply set the AllowSorting and AllowPaging properties to true and the work is done. The GridView control also offers improved ways to allow for editing of records as well as much better support for different controls used in columns rather than simple text.
Another new feature of the GridView is the EnableSortingAndPagingCallbacks property, which when set to true, will generate client-side scripting to handle the sorting and paging of the GridView without causing an entire page post back to the server. This is a nice addition for grid-intense Web pages and it functions much as an Ajax DLL would.
ReportViewer Control
The reporting functionality in .NET 2.0 has been revamped and enhanced. The ReportViewer, CrystalReportPartsViewer, and CrystalReportSource controls are used to design, generate, and display reports in a visual format that is much easier than anything used in .NET 1.x.
DetailsView Control
The DetailsView control displays a single record from a query at a time and does so with every field displaying on a separate row. The control has full functionality for inserting, updating, deleting, and paging and works great in combination with the GridView control explained above to give the user master-detail information on a query.
FormView Control
The FormView control is very similar to the aforementioned DetailsView, but rather than displaying all of the fields in rows, you display them in user-defined templates. The biggest difference here is that you have much more control over exactly how the data is displayed. It also has built in support for data binding, paging, inserting, updating, and deleting.
WebParts Controls
Finally, WebParts are one of the most exciting new features of ASP.NET 2.0. Ideal for portal systems and personalized Web sites, WebParts allow you to easily develop Web site sections that can be added, moved, deleted, etc., on an individual basis per user of your system. .NET 2.0 uses a slick client-side drag-and-drop technique to allow the user to move the WebParts around the page (see in Figure 3). WebParts can be dropped onto any WebPartZone control that you have set up on your page.
Other key controls used in WebParts are: