Introduction

I was really fascinated by the fantastic article I came across on the web. The article "Building Layered Web Applications with Microsoft ASP.NET 2.0" by "Imar Spaanjars" Building Layered Web Applications with Microsoft ASP.NET 2.0
helped me come up with my own four-tier, web-based Architecture using Ajax. While Imar's examples were made easy for the readers, I extended the BO (Presentation), BLL (Business Logic Layer), and the DAL (Data Access Layer) into Class Library projects and wrapped the entire application in a more structured way.

The purpose of this application is to implement the four-tier architecture and demonstrate the running of the application using a single housekeeping form.

Let us assume we have a database named "ACCOUNTS". This database contains a table Named "AccountTypes". In the below examples I will demonstrate:

How the application binds the "Grid View" using our custom List Collection Class (Inside the collection Folder of BO Library).

How the Insert and Select operations to the "AccountTypes" table are carried out from the client side using the xmlHTTP object. (AJAX)

How to dynamically build a table using the array retrieved by the XmlHTTP call. (AJAX)

Background

Using the code

Phase I

I will start off by creating a new Class Library Project for the Business Object (BO).

I will first create an AccountTypes.cs class. This will hold all the private variables to the class and public properties that correspond to the database fields.

In this project I have a separate folder called "Collections" for the Item Collections. I'll create a collection class AccountTylesList.cs which will inherit from its generic counterpart (List<accounttypes>)

I'll keep the constructor code empty, so that this can be filled up dynamically when required.

Your "BO" Project is ready for compilation. Building the project will give you BO.dll (Save this Library for future references)

Phase IV

Note: Phase IV can be skipped if you are interested in implementing Ajax in your application. Phase IV shows the basic usage of the functionality through code behind files.

Now that our three-tier architecture is ready, we only have to see the implementation and how things work using the below:

Create a new Web Project.

Add Reference of the previously compiled BO & BLL library to this project, and inherit the namespace "BO" & "BLL" in all your classes. Note that the DAL is completely hidden, and will not be accessible unless you add the DAL.dll to your references which is not required.

In the pageload, call the GetAccountTypeList Method using the AccountTypesManager Class. (Note that you wont have to instantiate any class) This will act as a datasource to your grid view control. "gvAccountTypes"

call the SaveAccountType Method using the accounttypesmanager class on the button click event in the code behind file.

Points of Interest

While retriving data to fill up the table dynamically, I was creating a two dimensional array (basically, its a string representing the array structure) and transporting it to the client side using a webservice.
Upon reaching the client side, JavaScript would interpret this as only string and not array.
I went crazy trying to find the problem. I found this really cool key word in JavaScript: "eval". Very Handy to use. eval did the trick for me.
The eval() function evaluates a string and executes it as if it was script code.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

my Visual Studio is not going to pick this project file.if i make IIS Virtural Directory ... and brows the site and click the button after creating the DB... it says OBJECT Set to Null Reference which is the most famous error