Wednesday, February 08, 2006

15 Seconds : Reusable Components in ASP.NET 2.0, Object Binding and Precompilation

15 Seconds : Reusable Components in ASP.NET 2.0, Object Binding and Precompilation

Introduction
One of the excellent features of ASP.NET 2.0 is the ability to create reusable components without having to compile them even once. This is possible with the addition of the new pre-defined directory named Code. The Code directory is a special directory that is used as a placeholder for storing all the reusable components. Any reusable component placed in this directory will be automatically referenced and made available to all the pages in the Web site. ASP.NET 2.0 not only makes creating reusable components easier, but also allows us to easily consume them by providing a new data source control named ObjectDataSource. With this new control, it is possible to bind to an output of an object's method directly to data-bound controls such as dropdownlist, gridview and so on.

Creating Reusable Components in ASP.NET 2.0
A cool and useful new feature in ASP.NET Whidbey is the addition of the \Code directory. The \Code directory, like the \bin directory, is a special directory used by ASP.NET, but with a twist. While the \bin directory is designed for storing pre-compiled assemblies used by your application, the \Code directory is designed for storing class files to be compiled dynamically at runtime. This allows you to store classes for business logic components, data access components, and so on in a single location in your application and use them from any page. Because the classes are compiled dynamically at runtime and are automatically referenced by the application containing the \Code directory, you don't need to build the project before deploying it, nor do you need to explicitly add a reference to the class, and you can easily make changes to a component and deploy it with a simple XCOPY or with a drag-and-drop operation. In addition to simplifying the deployment and the referencing of components, the \Code directory also greatly simplifies the creation and accessing of resource files (.resx) used in localization, as well as automatically generating and compiling proxy classes for WSDL files (.wsdl).

No comments: