Practical ASP.NET

Upgrading Sites to ASP.NET 2.0/3.5

It's good news, bad news if you're upgrading an existing site to ASP.NET 2.0 or 3.5. But it can be done.

First, the good news: Bringing an ASP.NET 2.0 site up to ASP.NET 3.5 is an almost trivial task. Open the site in Visual Studio 2.0, set the target framework to 3.5 in the Project's Property Pages | Compile | Advanced Compiler Settings, wait for the project to be closed and reopened, and then rebuild your site. You're done.

Now, the not-as-good news: Bringing an ASP.NET 1.1 site up to ASP.NET 2.0 or 3.5 is...problematic.

And a lot of organizations have sites that need to be upgraded from 1.1. Many of these 1.1 sites are applications that were started in 1.1 and were still under construction when ASP.NET 2.0 came out. Short deadlines being the reality of most projects, the development teams continued in 1.1, rather than take the time to convert to the new technology. Other applications were built under 1.1 and since those applications are, you know, working, the sites were left in 1.1. For any maintenance or enhancements, developers just make their changes in Visual Studio 2005.

But now that ASP.NET 3.5 is in general release, organizations are less willing to maintain two sets of development environments. Besides, ASP.NET 2.0/3.5 has so many goodies that it's hard to resist the temptation to upgrade even if a site doesn't actually "need" to be converted.

Easy Conversions from 1.1
As with converting from 2.0 to 3.5, the first steps in converting a 1.1 site is to open the site in Visual Studio 2005/2008 and then to rebuild.

The second step is to not be disheartened by the huge list of errors and warnings that appear in your Task List. Odds are that what you're seeing in the Task List are trivial problems repeated many times. With any luck, many of your problems can be replaced with a global search and replace.

For instance, names that were acceptable in 1.1 for methods or properties may now be considered in conflict with language keywords. One of my clients had, in a 1.1 site, a table with a field named "Operator." After the table was recreated in a strongly typed dataset in .NET 3.5, the field was renamed to "_Operator." Renaming all of the references to the field was time-consuming but not difficult. Often, name-related problems can be solved by enclosing the offending term in brackets (e.g., "[_Operator]").

In addition to actual errors, you can expect to get a wide variety of warnings. Almost everything that worked in 1.1 still works in 2.0/3.5 but some functionality has been depreciated. For instance, if you've been inserting JavaScript code into your page from server-side code, all of the methods you're using still exist but are now to be called from the Page's ClientScript property.

If you've been using inheritance as part of your Web site development, then you'll need to move your base classes to the App_Code folder (you may find that Visual Studio has already done that for you). If, for instance, you had an ASPX page that provided base functionality that all the other pages on your site inherited, you'll need to move the code file for that page to the App_Code folder (you can delete the ASPX file itself).

Awkward Solutions
Some problems are less "amenable to solution." Visual Studio 2003/ASP.NET 1.1 encouraged developers to use CSS absolute positioning when dragging and dropping controls on the page (at least, it encouraged me). ASP.NET 2.0/3.5 works best without absolute positioning, causing developers to fall back on old-fashioned tables to hold controls.

You probably won't notice or care unless you decide to migrate your pages to a Master Page. At that point, you'll probably find that your controls appear to be "shifted" and you'll need to adjust your controls' positions.

In ASP.NET you could access another page in the same application as an object. Frequently, developers would pass data to the next page in a workflow or to a User Control by accessing properties or methods on the next page before transferring to it. This code was acceptable in 1.1 to load a User Control and set a public property on the User Control named CustomerId:

Dim c As MyUserControl
c = CType(LoadForm("MyUserControl.ascx"), MyUserControl)
c.CustomerId = Me.CustomerIdTextBox.Text

Frequently, developers used this technique to pass data to a page or user control before the page's Load event fired.

In ASP.NET 3.5, it's no longer possible to access the class associated with another page or user control. There are several solutions to the problem, including storing the data in a Session variable before transferring to the other page, using a querystring in the URL passed as part of calling Server.Transfer/Response.Redirect, or adding code in the destination page that reaches back to the original page through the PreviousPage property. Since ASP.NET 2.0/3.5 offers the PreInit event, which occurs before the Load event, the data can be retrieved earlier in the page's life cycle.

Having said all that, upgrading a 1.1 site to 2.0/3.5 can be surprisingly painless. For all but the largest sites, setting aside a week will probably let you do the conversion and test your application.

But, who knows? I may have missed something. Have you got any conversion "gotchas" to share? E-mail them to me at [email protected] and I'll roll them into a future column.

About the Author

Peter Vogel is a system architect and principal in PH&V Information Services. PH&V provides full-stack consulting from UX design through object modeling to database design. Peter tweets about his VSM columns with the hashtag #vogelarticles. His blog posts on user experience design can be found at http://blog.learningtree.com/tag/ui/.

comments powered by Disqus

Featured

  • Compare New GitHub Copilot Free Plan for Visual Studio/VS Code to Paid Plans

    The free plan restricts the number of completions, chat requests and access to AI models, being suitable for occasional users and small projects.

  • Diving Deep into .NET MAUI

    Ever since someone figured out that fiddling bits results in source code, developers have sought one codebase for all types of apps on all platforms, with Microsoft's latest attempt to further that effort being .NET MAUI.

  • Copilot AI Boosts Abound in New VS Code v1.96

    Microsoft improved on its new "Copilot Edit" functionality in the latest release of Visual Studio Code, v1.96, its open-source based code editor that has become the most popular in the world according to many surveys.

  • AdaBoost Regression Using C#

    Dr. James McCaffrey from Microsoft Research presents a complete end-to-end demonstration of the AdaBoost.R2 algorithm for regression problems (where the goal is to predict a single numeric value). The implementation follows the original source research paper closely, so you can use it as a guide for customization for specific scenarios.

  • Versioning and Documenting ASP.NET Core Services

    Building an API with ASP.NET Core is only half the job. If your API is going to live more than one release cycle, you're going to need to version it. If you have other people building clients for it, you're going to need to document it.

Subscribe on YouTube