asp:feature
LANGUAGES: VB .NET | C#
TECHNOLOGIES: Objects and Classes | ADO.NET
3 Things ASP.NET Experts Wish They'd Known Right From the Start
Avoid a little agony by learning from the mistakes of others.
By Ken McNamee
Lots of developers - even intermediate and senior ASP Classic developers - struggle as they try to learn ASP.NET. Of course, it's possible to make a few changes to an ASP Classic page or application and get it working under ASP.NET, but that's not really learning ASP.NET development. To become an intermediate or senior ASP.NET developer, you've got to forget most of the tricks and techniques that got you by in ASP Classic and embrace the new object-oriented .NET paradigm. Here are three things you can do to get the most out of ASP.NET.
Do Objects and Classes the .NET Way
Many ASP Classic developers are familiar with creating Visual Basic 6.0 DLLs, using Server.CreateObject to instantiate a class within the component from an ASP page, running a method, then releasing the object. The common scenario was to use two very different environments: Visual InterDev to develop the ASP pages, and Visual Basic to develop the components. Unfortunately, this might have increased the learning curve as you unlearn the ASP Classic techniques that have become so familiar.
What can make learning object-oriented (OO) development in .NET so difficult is that although later versions of Visual Basic let you create classes, the classes aren't fully object-oriented; you can't use them as a foundation for a new class, which is a process called inheritance. In ASP.NET, though, you have full OO capabilities, including the ability to create new classes that inherit from others. In fact, every page you create will inherit from the System.Web.UI.Page class automatically by default. Or you can create your own class that all pages inherit from and include custom business logic or user interface designs that can be reused over and over without coding them into every page.
It's definitely to your advantage to think about your ASP.NET pages more as objects to manipulate programmatically and less as text files to be parsed by the ASP engine.
ADO.NET is Not ADO
Just like ASP.NET is a complete rewrite of ASP Classic, ADO.NET is a complete rewrite of ADO Classic. As if moving from non-OO VBScript or limited-OO Visual Basic wasn't hard enough, you also are faced with completely rethinking the way you access data. ADO 2.7 and prior contained the familiar ADODB.Connection and ADODB.Recordset objects for which most developers could write the boilerplate code in their sleep. Although these objects don't exist in ADO.NET, conceptually the process of accessing the database and retrieving the data via a network stream or in one large chunk remains the same.
The Connection and Recordset objects still exist in ADO.NET, but they are called something else and have many more capabilities than their ADO Classic counterparts. For instance, the DataSet object in ADO.NET is somewhat analogous to the Recordset, but your options for dealing with disconnected data and transformations to and from XML are vastly superior. It might be possible to use ADO Classic from .NET, but it wouldn't be wise. The quicker you learn all the intricacies of ADO.NET, the better off you'll be.
VB .NET or C#?
I've seen so many developers stress out unnecessarily over whether to learn VB .NET or C# when, in reality, it's a moot point. The learning curve to ASP.NET development is not so much in the language changes as in the API or platform changes. I spend most of my time writing C# code, but I wouldn't really describe myself to others as a C# programmer. I am simply a .NET developer, and because I know the .NET Framework API fairly well, I can easily read and develop in VB .NET, J#, and even COBOL .NET. Sure, there are some syntactical hurdles to overcome and I find myself putting semicolons at the end of my VB .NET lines, but those problems pale in comparison to the cross-language issues in the pre-.NET days. Spend more of your energy learning the class library and less time worrying about which syntax you use. After all, it all gets compiled to Microsoft Intermediate Language (MSIL) anyway. If you want a real challenge, learn to read and write in MSIL; then you'll be able to call yourself a hard-core .NET developer.
Ken McNamee is a senior software engineer with RelayHealth Corp., the premier provider of secure, Web-based doctor-patient communication services. Prior to this, he led a team of developers in re-architecting the Home Shopping Network's e-commerce site, HSN.com, to 100 percent ASP.NET with C#. E-mail him at mailto:[email protected].