ASP.NET
Summing Up the New ASP.NET Controls
ASP + .NET 2.0 = productivity
Mar. 12, 2006 03:30 PM
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:
- HotSpotMode: An enumeration indicating whether to have mouse clicks navigate to a URL or generate a postback.
- HotSpots: A collection of Circle-HotSpot, RectangleHotSpot, and PolygonHotSpot objects. These objects derive from the HotSpot object and contain properties for a URL and target if using the navigate HotSpotMode or a property for a postback value if using the postpack HotSpotMode. There is also a HotSpotMode property on the HotSpot object to allow you to have multiple hot spots performing differently.
BulletedList Control
The BulletedList control is simply a way to provide easy generation of dynamic bulleted lists. The control can be data bound to a data source and gives you a number of bullet customizations, including circle, square, numbered, alpha, roman numbers, and custom image.
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:
- Login: The Login control contains text boxes for username and password as well as a "remember me" checkbox. The control is auto-wired for authentication using .NET memberships and no code is required if you go that route. If you store your authentication in another way, you can modify the control to run your methods.
- LoginView: The LoginView control is a view that allows you to toggle automatically between two different sub views - one for authenticated users and one for anonymous users. This is very handy for content panes that change information based on whether a user is currently logged in or not.
- LoginStatus: This control displays a login link or a logout link based on the user's current state. The control offers full visual customization.
- LoginName: This control displays the name of the currently logged in user.
- PasswordRecovery: This control allows a user to retrieve his password based on an e-mail used in registration. If the .NET memberships are stored using non-reversible encryption, a new password is generated and sent instead. You can also set the system up to use a security question before e-mailing the password to the user.
- ChangePassword: This control allows the user to modify his/
her password by first providing the original password and then creating and confirming a new password.
- CreateUserWizard: This control creates a new .NET membership for a user by collecting information such as username, password, e-mail, etc.
GridView Control
The GridView control is essentially a revamped and beefed-up DataGrid control. Those of you who are familiar with the .NET 1.x DataGrid control realize that it was fantastic for quick data binding in a grid, but for extended functionality such as paging, sorting, editing, etc., it left a bit to be desired.
About Aaron ReedAaron Reed is an assistant professor specializing in software architecture and design and .NET development at Neumont University in Salt Lake City, UT. He has worked professionally in the industry for over 12 years as a lead architect/designer, development manager, and VP of development. When he isn't spending time reading up on the latest in software development, Aaron loves spending time with his beautiful wife and three children.