Getting Started with ASP.NET 2.0

Introduction

First, some background. I’ve been working with ASP.NET 1.0 for some time now, and it’s a good framework for putting together useful web applications and sites. Recently, I’d been reading up on some of the new features in the newer version. There’s been a lot of hype over it - and for good reason. Over the Christmas holidays, I decided to install Visual Studio 2005 (standard edition) and start tinkering with ASP.NET 2.0.

I followed some tutorials on the web on using these new technologies, and was immediately impressed. Both Visual Studio 2005 and ASP.NET 2.0 seem easy to use, and have plenty of features to keep one busy experimenting for a long time. I can’t say so much about SQL Server 2005 yet, as I haven’t used it too much. All in good time.

The following sections will detail some specific items that I have immediately found useful, and will be sure to use in the future.

Visual Studio 2005

I have read that many people have had difficulties in using the new version of Visual Studio, although (supposedly) most of them have been fixed with the recent Service Pack 1 update. I had no problem installing the software - it took just over half an hour, surprisingly about half the time needed to install 2002 on the same computer.

Installing SP1, on the other hand, was very time consuming. On this computer it took a full hour to update a product that only needed 30 minutes to install initially. Rather strange, although I understand that many updates and fixes are being applied during the update process.

After the installation was all done, I was able to use VS 2005 without difficulty. It starts pretty quickly, and I have no problem using it. A number of things have changed since 2002 (I never needed to bother with 2003), so I’ve got some exploring to do. One thing I will need to get used to is how each project seems to automatically have sections labeled App_Code, App_Data, and App_Themes, a little different than what I’m used to. Progress, I guess…

One thing I do like is how a black horizontal line is automatically drawn between each function in a code file. This helps to quickly see how functions and properties are separated.

Master Pages

ASP.NET 2.0 provides a system called Master Pages that allows you to create, in a single file, a standard page layout, with common stylesheets, scripts, images, sidebars, and so on. Any pages in the site using that standard master page will be the same in layout and appearance. So convenient! It’s also nice that you can use multiple master pages in one site (you can tell an individual page to use a specific master page template), so different pages can have different appearance or layout, as necessary. One use of this is having different page templates for the public part of a site, and a private administration section. Yet another benefit of master pages is that they can themselves have embedded web controls - they’re not limited to static content!

ASP.NET 1.0 is missing exactly this functionality. I did a lot of reading on the subject, and there were a few workarounds for the problem. One was to use custom controls to define distinct sections of the page, but that came with problems of its own. There was also an option of extending the usual Page class and writing a custom Render function. The solution I settled on was Wilson.MasterPages, which more or less emulates the Master Page functionality of ASP.NET 2.0. It wasn’t an ideal solution, but it seemed the best of the bunch, and it DID work, so I stuck with that.

Bottom line here, I’m likely to make a move to ASP.NET 2.0 for master pages alone! Any time I start a new project in ASP.NET 2.0, possibly the first thing I will do is set up my custom page templates!

Site Navigation

A critical part of any website is the navigation system. This is present in many forms, including a tree view of links, a vertical navigation bar, a horizontal navigation bar, and even breadcrumb paths.

ASP.NET 1.x does not have specific controls for these purposes, so it is necessary to manually create a list of links, OR build your own controls for automatically building a list of links.

ASP.NET 2.0, however, has three controls to address this need: the SiteMapPath, the Menu, and the TreeView.

The SiteMapPath control builds a list of breadcrumb links, which is useful to indicate where in a site’s hierarchy the current page is. It also includes links to pages above the current one in the site hierarchy.

The Menu control builds - what else - a menu of links for each page in the site. This can be set to be horizontal or vertical.

And last, the TreeView uses the common “tree” paradigm, where a hierarchical list of links is displayed. This is usually intuitive since it clearly shows different sections of the site, and the pages in each section. It can however be difficult to use if it gets quite large.

There is actually one other factor in the way these controls work: they make use of the website sitemap. The sitemap is usually an XML-formatted document (although it seems to be possible to store this information in a database, or base it off the filesystem structure) containing a list of siteMapNode elements. There is a single top-level node representing the overall site, then inside that node are any number of child nodes, each representing a section of the site. And within those nodes will be yet more nodes, either representing single pages or sections deeper in the site’s hierarchy. By maintaining this document when adding or removing pages, the navigation controls will be able to automatically generate their content using the sitemap document. Very convenient.

The sitemap is connected to the navigation controls through a new data source control called the SiteMapDataSource. This control provides the necessary information to the matching navigation control, which then generates the menu or list. Only the Menu and TreeView need to be bound to this control; the SiteMapPath, interestingly, does not. I guess it just automatically makes that assumption of using the sitemap data.

(More) Advanced Data Binding

In ASP.NET 1.0, one of the best new features was the data-bound web controls. This was a real time-saver over the old way of doing things in Classic ASP. As an example, to display a table of information from a database, you had to manually loop through all the rows, and then all the columns, building each section one by one. ASP.NET allows to bind a similar database results table directly to a DataGrid web control, which would then automatically retrieve and display all the data. The same can be done, in much the same way, with common form elements, such as textboxes, radio buttons, and drop down lists, to name a few. This was a big improvement over the old way.

ASP.NET 2.0 takes this further, by providing yet even more databound form controls, and simplifying and extending the ways in which the controls can receive their content information. There’s more control, more flexibility, and more variety. You can even bind custom objects to controls, by providing properties and methods in the objects to be used by the controls to receive data. The business objects can then encapsulate the details involved in retrieving data in the first place. In my opinion, this is the next best new feature in ASP.NET 2.0 after master pages.

SQL Server 2005

I haven’t used SQL Server 2005 much at this point, so there isn’t much I can say about it yet. You can do pretty much the same in it as with other databases, although in different ways. Although I understand it has better support for the .NET framework, in that it can work directly with the .NET Common Language Runtime (CLR). Another interesting new feature is it’s new datatype for XML content. You can store actual XML in the XML-typed column, and then retrieve the whole XML itself, or use XPath to look up a particular part of it. Sounds like it could be useful for storing an unknown amount of information in a single column, although it could get pretty big. I’ve read one example where it can be used to store the table of contents - or index - for a book, and then search through it for a particular term.

Conclusion

The preceding sections described some of the features I immediately liked or found useful while starting to dabble with ASP.NET 2.0 and the related software. The list is hardly comprehensive, and no doubt would grow quite a bit as I get further into learning the new systems.

As mentioned above, I particularly like the new Master Pages functionality - I’ll be sure to get a lot of use out of it!

I imagine that when I start on a new web project, I’ll be thinking of doing it in ASP.NET 2.0, with help from Visual Studio 2005. Time to move forward.

Additional Reading

These links lead to some of the useful tutorials I followed, or resources I referred to, during my initial foray into the world of ASP.NET 2.0. They’re worth visiting and bookmarking.

1 comment to “Getting Started with ASP.NET 2.0”

  • #1

    State of the Blog: 2007 | GrantPalin.com

    [...] Started working with ASP.NET 2.0 - This is still a work in progress; however, I like what I see so far. But Microsoft have recently gone and released ASP.NET 3.5! Ay yi yi, I’m well behind now! Fortunately, .NET 3.0 and 3.5 are just additive layers of new features on top of 2.0, so when I get 2.0 licked, there hopefully won’t be too much further to go to get current with .NET. [...]

Make a Comment

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>