ASP.NET 3.5 Specific Features
I will start with the ASP.NET 3.5 specific features and then move on to the ASP.NET 3.5-related Visual Studio 2008 enhancements. I'll first discuss a couple new controls added to ASP.NET 3.5, starting with the ListView and the DataPager.
The ListView Control
Imagine that you could have an ASP.NET control with the free form templating capabilities of the Repeater control and the data editing capabilities of the DataGrid control. Imagine no more because that control exists in ASP.NET 3.5—the new <asp:ListView>
The ListView supports data binding to all the traditional data sources such as SQLDataSource, ObjectDataSource, XMLDataSource as well as the new LinqDataSource.
You have complete control of how the ListView presents your data through the use of 11 templates.
The two most important templates are the LayoutTemplate and the ItemTemplate. The LayoutTemplate is the outer shell containing the HTML that defines the overall look and feel of the control while the ItemTemplate contains the HTML that specifies how each bound record will appear.
The markup you use for the LayoutTemplate could be very simple or very complex. In either case, the LayoutTemplate needs to know where to place the rendered code for the ItemTemplate. You do this by adding a server-side control to the LayoutTemplate and assigning its ID to "ItemPlaceholder" and while that exact name is required, no, it is not case sensitive, as shown in the basic ListView code below:
Text='<%# Eval("CompanyName") %>' />
Text='<%# Eval("City") %>' />
Alternatively, you can specify the name of the placeholder control by setting the ListView's ItemPlaceHolderID
property to the name of the control. Either way, the LayoutTemplate needs to know where the content rendered by the ItemTemplate (and all other templates) is supposed to go.
The ItemTemplate in the preceding code uses labels to display the CompanyName
for each entry in the Customer
Now I'll move from a simple example to an example complete with the ability to insert, update, and delete data. I used the ListView's smart tag option (see Figure 1
) to configure the data capabilities as well as the look and feel I wanted for this sample (see Figure 2
). The result is a ListView complete with the templates that control the formatting for adding, updating, and (deleting records in the ListView (see Listing 1
|Figure 1. Configure ListView: Select Configure ListView for ListView configuration options.||
|Figure 2. ListView Configuration Options: The options include selecting a layout, style, data updating options, and paging.||
What if the result set being returned from your data source is large (over 100 records)? Straight out of the box, the ListView control does not support paging, but that is not a problem because it does work hand-in-hand with the new DataPager control.
The DataPager Control
|Figure 3. DataPager with Paging Options: Here's a Web page utilizing the DataPager control and the NextPreviousPagerField and NumericPagerField options.|
As its name states, the <asp:DataPager>
control provides paging capabilities. It is an external control that points at the control it provides paging support for. As an external control, you gain the advantage of being able to place it anywhere on the page (or as many as you want on the page) and configuring what it is going to look like. The DataPager works with controls that implement the IPageableItemContainer interface. At the moment, the DataPager only works with the new ListView control because it's the only one that implements the IPageableItemContainer interface.
In Listing 2
I have extended the basic ListView sample code by adding a DataPager. The DataPager's PageControlID
specifies which control the DataPager will provide paging support for, ListView2 in this example. The PageSize
setting determines how many rows of data will be displayed on each page; five in this example. There are three different types of field controls available, NextPreviousPagerField, NumericPagerField, and TemplatePagerField. This sample in Listing 2
uses both the NextPreviousPagerField and the NumericPagerField (see Figure 3
The NextPreviousPagerField provides an interface for users to move from page to page or jump to the first or last page (see Figure 4
). The NumericPagerField provides an interface for users to select a page by page number (see Figure 5
). The TemplatePagerField provides a mechanism for you to develop a custom paging interface.
The LinqDataSource Control
|Figure 4. NextPreviousPagerField: The figure shows the process of adding the NextPreviousPagerField in the Source window.||
|Figure 5. NumericPagerField: Here's how you add a NumericPagerField in the Source window.||
control is an ASP.NET control that, like the <asp:SqlDataSource>
controls, is used to declaratively bind ASP.NET controls to a data source. What makes the LinqDataSource unique is that instead of binding directly to something such as a database or data access layer object, which you can still do, you bind to a LINQ-friendly data model such as a LINQ to SQL object relational model (ORM). For more LINQ to SQL info, Microsoft's Scott Guthrie has a great five-part series on his blog
Integrated AJAX Support
|Figure 6. No AJAX Templates: The new Web site dialog box does not contain AJAX-specific templates.|
Back in the day before Microsoft released ASP.NET 3.5, you had to download and install the Microsoft ASP.NET AJAX 1.0 framework to build or deploy an AJAX-enabled application. But those days are gone now, because AJAX is now treated as a first-class citizen in Visual Studio and the libraries are now included in .NET 3.5. When you build a new Web site, you no longer need to specify an AJAX-ready Visual Studio project template (see Figure 6
One of my initial concerns when installing Visual Studio 2008 was how well it and NET 3.5 would coexist on my machine, which already contained Visual Studio 2005 and related installed extensions, such as AJAX 1.0 and .NET 3.0. Fortunately, when you create a new Web Site project or new ASP.NET Web Application project, the 3.5 version of the System.Web.Extensions assembly containing the AJAX libraries gets added automatically as a project resource. Because System.Web.Extensions v3.5 is a superset of System.Web.Extensions v1.0 your AJAX 1.0 code should run unchanged in v3.5.
Improved Designer Support for AJAX Control Extenders
AJAX control extenders provide a way to add capabilities and functionality to controls already on a page. The ASP.NET AJAX Control Toolkit
is a great community-driven collection of free control extenders that you can use to easily add AJAX functionality to your pages.
With Visual Studio 2005, you had to manually wire up the controls with the extender control you wanted to use. Visual Studio 2008's improved designer support for ASP.NET AJAX control extenders has made the process much easier by providing Smart Tag options to add or remove extenders from a particular control (see Figure 7
). When Visual Studio 2008 detects that one or more extenders exist for the control you have selected it will display the control's Smart Tag. Selecting Add Extender will display the Extender Wizard for you to select which extender you would like to use (see Figure 8
|Figure 7. Add Extenders: When Visual Studio 2008 detects extenders are present for a control, Add Extender is added to the Smart Tag options.||
|Figure 8. Selecting Extenders: You can select an extender for a specific control type.||