Introduction to ASP.NET - OO Is at the Heart of Every ASP.NET Page
(Page 7 of 10 )
One of the coolest things about object orientation in ASP.NET is that you don’t have to know much about how to use it since most of it is under the covers for basic page development. Every ASP.NET page implicitly inherits from the Page class of the System.Web.UI namespace, which provides access to all ASP.NET implementations of the intrinsic objects that were introduced in classic ASP, such as Request, Response, Session, and Application, and to a number of new properties and methods. One advantage of this is that each page is compiled into an assembly based on the Page class, providing substantial performance improvements over classic ASP, in which code was interpreted at runtime.
Object orientation is also the key to another important new feature of ASP.NET: code-behind. Code-behind allows developers to separate executable code from the HTML markup that makes up the user interface. Executable code is placed in a module called a code-behind file, which is associated with the ASP.NET page via an attribute in the page. The code-behind file contains a class that inherits from the Page class. The ASP.NET page then inherits from the code-behind class, and at runtime, the two are compiled into a single executable assembly. This compilation allows a combination of easy separation of UI and executable code at design time with high performance at runtime.
Choosing a Language Choosing which language to use when developing ASP.NET applications is both easier and harder than choosing a language for classic ASP development. It is harder because it may be intimidating for some to choose between a substantially revised Visual Basic and a completely new language, C#. It is easier because the choice of language no longer requires giving up substantial amounts of functionality for your preferred language.
As in many other cases, including language choice in classic ASP, a lot of the decision is determined by where you’re coming from. If you’re:
An experienced ASP developer who has used VBScript -- You’ll probably prefer Visual Basic.NET.
An experienced ASP developer who’s used JScript -- You’ll want to look at C# or JScript.NET (keeping in mind that finding code examples in C# is easier, since the novelty of the language makes it more interesting for many).
An experienced Visual Basic developer -- Visual Basic.NET is the obvious choice, but you may also find it worthwhile to check out C#, which offers a lot of the power of C++ without such a steep learning curve.
An experienced C, C++, or Java developer -- You’ll probably feel right at home with C#, which, as a C-derived language, shares a lot of syntax with these languages.
New to ASP.NET development, with no prior ASP experience -- Visual Basic.NET will probably be easiest to learn, although C# runs a close second.
Because of the level of cross-language interoperability in .NET, your choice needn’t be an either/or. You can feel free to create applications and classes in Visual Basic.NET, C#, JScript.NET, or any .NET-enabled language, knowing that they will be able to work together smoothly and easily, thanks to the CLR.
Why and When Would I Use ASP.NET? You should use ASP.NET for any new projects you are about to start for the following reasons:
- Reduced development time
- Increased performance
- Increased application stability
- Increased scalability
- New ASP.NET features (see the discussion later in this chapter)
Some of these benefits, such as reduction in development time, assume familiarity with the .NET development platform. If you are starting your first ASP.NET development project, you should allow some time for getting up to speed on the new platform. Subsequent projects should see reduced development time over classic ASP, as developers become more familiar with the platform.
In addition to these factors, ASP.NET, like ASP, is available for free. The only costs associated with ASP.NET development are the costs of the operating system on which you wish to run your application (Windows 2000, Windows XP, or Windows Server 2003) and the cost of the development environment you choose to use. Of course, as with classic ASP, you can use free or inexpensive text editors to create your applications. Given that the .NET Framework is a free add-on to Windows (and is integrated with the Windows Server 2003 line), it is possible to create ASP.NET applications without spending a penny beyond the cost of the operating system and hardware on which it will run. Integrated development environments, such as Microsoft Visual Studio .NET 2003, are also available at an additional cost and greatly simplify ASP .NET development.
 | If you've enjoyed what you've seen here, or to get more information, click on the "Buy the book!" graphic. Pick up a copy today!
Visit the O'Reilly Network http://www.oreillynet.com for more online content. |
Next: Porting an Existing Application to ASP.NET >>
More ASP.NET Articles
More By O'Reilly Media