Enterprise Web Applications using ASP.NET 2.0

Well, most of the web developers today develop Enterprise Web Applications.  While the challenge lies on different parameters like designing the different layers, transferring data between the different layers etc., let us examine how Visual Studio 2005 and ASP.NET 2.0 help you create Enterprise Web Applications quite easily.

Designing your Data Layer

The first step in designing your application would obviously be designing your database and I would leave that part entirely at your discretion.  Once you have your database ready, say you designed a SQL Server 2005 database, the next thing that you would want to do is designing your Data Access Layer.  Now we immediately jump into using different modeling tools and design nice use cases / activity diagrams, class diagrams etc.,  While Visual Studio 2005 Team System allows you design Class Diagrams, etc., and export them for documentation, I again leave this part if you are using an external design tool.  In most of the application scenarios, I have found Visual Studio and Visio mostly sufficient.

Designing the Data Access Layer using Visual Studio 2005 - Data Set Template

Start Visual Studio 2005 - Select File - New Website and chose a location and specify a name for your website, say EntWebApp.

This would create a basic ASP.NET Website with a Default.aspx page, Web.Config file etc.,  The next thing to do is to select - Add - New Item - DataSet and provide a name say CustomersDAL. 

It would prompt you to save the file in the App_Code folder.  The App_Code folder is new in ASP.NET 2.0 which allows you to place class files which are compiled dynamically at run time as well as be accessible across the application.

Once you click "yes", it creates a CustomerDAL.xsd file with a visual interface to design the Data Access Layer.  Using Server Explorer (View - Server Explorer), connect to the Database server node and navigate to your particular database say "NorthWind" Database.

There after, you can drag and drop the tables and start configuring them.  The Data Set designer provides you all the relational information as well as exposes the Table fields as properties for each Table embedded into a Table Adapter.

Say you designed your Customers Table as CustomersDALTableAdapter.   It prompts you to configure your connection string and you can configure the connection string that can be stored in the web.config file.  Once you complete this step, you can chose the table and also specify the columns to be returned.  You could do this in different ways.  You can either chose SQL queries, or Create New / Use Existing Stored Procedures in the Database.  Once you do that, you have your first DataAccess Method (Query) ready.  You can add multiple methods to it by clicking on "Add Query" and configure as many retrieval jobs you would want to accomplish.  You could also drag and drop more tables from the server explorer and configure them.

Designing your Business Class Methods (Middle Tier Components)

Once we are done with our Data Access Layer, we need to start designign your middle tier components.  We have different approaches today in designing our middle tier components.  We create a Business Layer and probably a Business Facade layer or simply go with a Business Layer.  In this case, we will have a Business Layer which is designed as a C# class file.  We could also use VB.NET to accomplish this, as well as use a Class Library Project to add more business methods.  But for the sake of simplicity I am going to have one class file.

Right Click the Website root, select -  Add New Item - select Class template and create a CustomersBL.cs file.  Note that this file would act as our business layer. 

So far, we haven't written any line of code and so pretty much easy.  In this business layer, we want to write a couple of methods which would help in a. implementing our business logic if any and use the CustomersDAL that we created using Table Adapter Configuration Wizard.

In the CustomersBL.cs file, we would write the following code snippet

public DataTable GetCustomers()

{

CustomersDALTableAdapters.CustomersTableAdapter customersDB =

new CustomersDALTableAdapters.CustomersTableAdapter();

// Implement any business logic here

return customersDB.GetData();

}

public DataTable GetCustomerByCustomerID(string customerID)

{

CustomersDALTableAdapters.CustomersTableAdapter customersDB =

new CustomersDALTableAdapters.CustomersTableAdapter();

// Implement any business logic here

return customersDB.GetDataBy(customerID);

}

Note that I have left the commented portion for any business logic you would want to implement.  If we examine the above code snippet, we could figure out that we have programmatic access to the Table Adapter we created and it provides you the typed flexibility to call methods defined in your DAL Layer.

Once we are done with the above, we just need to build the website once to check for any errors / issues. 

Designing your UI Layer

Now we come to the part of designing the UI Layer.  We already have the Default.aspx page which is created when we created the website.  We could use the same page or add a new webform as appropriate and then add a GridView control from Toolbox - Data section.  Switch to Design mode if you are in source view.  This allows you to configure the GridView's databinding properties.

Once you hover over the GridView in design mode, you get the smart tag option to chose and configure the GridView properties.  Select "Chose Data Source' - "New DataSource" and in the prompted list, select "ObjectDataSource".  The next UI would provide you with a list of Business Objects and a checkbox named "Show only Data Components".  Uncheck the checkbox so that it also shows the Business Layer Class we created.

You can select the CustomersBL that we created and the next screen allows you to "Choose your Method".  Select the GetCustomers that we had written in the Business Layer.  Once you click "Finish" you can format the GridView by selecting the Auto Format and selecting a scheme.  Also you could enable Paging, Sorting and Selection from the same wizard.  With that we are good to run the page and once you run the page you would be able to find that the Customers Records are displayed in a paged manner.

Next you would want to link the GridView to a Details View control to have a master-detailed view of the records.  To do that add a new Details View control to the page.  Configure it to use a new Object DataSource and repeat the steps as we did for the GridView, except that in the "Choose your method" screen you must choose GetCustomerByCustomerID since we would try to retrive a particular Customer Record.

You would be prompted with an additional screen to chose the input parameter settings since this method requires an input parameter.  You can chose the parameter source and in our case it is "Control" and the ControlID is "GridView1".  Also we need to specify a default value 0.

We need to do one additional step.  Select GridView properties and specify "CustomerID" in the DataKeyNames property for the GridView.

When we run the page, we initially see only the GridView neatly paged and showing the first set of records.  Upon clicking on "Select" we would be able to see the DetailsView of the selected record.  (In case you don't see the "Select" option, you might have missed "Enable Selection" in the GridView configuration)

This page now provides a kind of Master-Detailed View of the Customers Record and it retrieves data from Database using TableAdapter, Business Layer and Object DataSource which makes it a three tier architecture and thereby an Enterprise Web Application Architecture.

Cheers !!!

Print | posted on Tuesday, November 27, 2007 1:55 AM

Comments on this post

# re: Enterprise Web Applications using ASP.NET 2.0

Requesting Gravatar...
Test Comment
Left by Harish Ranganathan on Nov 27, 2007 2:08 AM

# re: Enterprise Web Applications using ASP.NET 2.0

Requesting Gravatar...
Good webcast
Left by Nahid on Nov 27, 2007 8:20 PM

# re: Enterprise Web Applications using ASP.NET 2.0

Requesting Gravatar...
Nice demo app for very small companies. At least you didn't pop it into a GridView and cache the DataSet to prevent round trips. This works on a small set of data, but not for large "Enterprise" applications. You can't be serious about storing your connections in the web config let alone using a DataSet for a large "Enterprise" application. Does Microsoft or you toss DataSets around internally to pass data for any large scale in-house apps? Just curious to see another tiny app passed of as a scalable "Enterprise" application.
Left by Coleman on Nov 28, 2007 5:51 AM

# re: Enterprise Web Applications using ASP.NET 2.0

Requesting Gravatar...
Why would you start by designing your data and data access layer BEFORE you "immediately jump into using different modeling tools and design nice use cases / activity diagrams, class diagrams"? The whole point of Use Cases is to document how the users "use" the system in order to have that drive your design...all of your design: user interface design, data design, class design, everything?

How do you manage to get a list of entities and attributes in order to design your tables?

Your entire article, I think, is completely backwards. The most important part of any system is creating tools that allow the user to do what they need effectively and efficiently. No one cares what your data model looks like except your DBAs and only then if you start having performance issues.

Designing applications like this is probably why so many business applications look like a DB to Screen code generation tool was clicked once too many times :) The further away from the user's direct interaction, the less they (and you) should care about what is going on. OneNote finally got persistence right from a user perspective: there is none...
Left by Russ McClelland on Jan 09, 2008 10:18 AM

# Great Practical Tips

Requesting Gravatar...
Very comprehensive guide on using ASP.NET 2.0 to create enterprise web applications. Anyone need to do it should read this guide.
Left by Making Money on Nov 21, 2009 6:03 PM

# re: Enterprise Web Applications using ASP.NET 2.0

Requesting Gravatar...
"Very comprehensive guide on using ASP.NET 2.0 to create enterprise web applications. Anyone need to do it should read this guide." - Absolutely agree. Very useful information.
Left by make money on Jan 22, 2010 3:53 PM

# re: Enterprise Web Applications using ASP.NET 2.0

Requesting Gravatar...
Good webcast
Left by registry cleaner on Feb 21, 2010 6:11 PM

# re: Enterprise Web Applications using ASP.NET 2.0

Requesting Gravatar...
"Very comprehensive guide on using ASP.NET 2.0 to create enterprise web applications. Anyone need to do it should read this guide." - Absolutely agree too. Very useful information.
Left by best registry cleaner on Feb 22, 2010 1:14 AM

# re: Enterprise Web Applications using ASP.NET 2.0

Requesting Gravatar...
Great info.I like all your post.I will keep visiting this blog very often.It is good to see you verbalise from the heart and your clarity on this important subject can be easily observed.
Left by insanity workout on Mar 02, 2010 11:14 AM

# re: Enterprise Web Applications using ASP.NET 2.0

Requesting Gravatar...
Very comprehensive and concise guide-just what I needed!
Left by bankruptcy law attorney on Mar 05, 2010 1:46 PM

# re: Enterprise Web Applications using ASP.NET 2.0

Requesting Gravatar...
this is a very good post
Left by tourmaline on Apr 11, 2010 10:58 AM

# re: Enterprise Web Applications using ASP.NET 2.0

Requesting Gravatar...
nice Webcast you have here.
Left by voiture thermique on May 05, 2010 5:35 AM

# re: Enterprise Web Applications using ASP.NET 2.0

Requesting Gravatar...
i agree with the comment above, this post is right on point.
Left by tracteur tondeuse on May 16, 2010 2:49 PM

# re: Enterprise Web Applications using ASP.NET 2.0

Requesting Gravatar...
ALINMASI GEREKEN BİR ÜRÜN KULLANIN
Left by meksika biberi zayıflama hapı on May 31, 2010 11:21 PM

# re: Enterprise Web Applications using ASP.NET 2.0

Requesting Gravatar...
That is some inspirational stuff. Never knew that opinions could be this varied. Thanks for all the enthusiasm to offer such helpful information here.
Left by beachbody coach on Jun 08, 2010 10:42 AM

# re: Enterprise Web Applications using ASP.NET 2.0

Requesting Gravatar...
Great guide. I'm glad I found this on google.
Left by Pool games on Dec 05, 2010 8:40 PM

# re: Enterprise Web Applications using ASP.NET 2.0

Requesting Gravatar...
Great guide thanks for sharing this!
Left by see now on Nov 29, 2012 3:53 PM

# re: Enterprise Web Applications using ASP.NET 2.0

Requesting Gravatar...
thank you very much, this is the information I need. I hope this website always give the information quality.
Left by tas sofa on Nov 30, 2012 7:12 PM

# re: Enterprise Web Applications using ASP.NET 2.0

Requesting Gravatar...
thanks for post it
Left by Mark on Jan 29, 2013 8:25 PM

# re: Enterprise Web Applications using ASP.NET 2.0

Requesting Gravatar...
thank you very much, this is the information I need. I hope this website always gave the information quality.
Left by http://parfumchristianjornald.bl on Jun 20, 2014 8:54 AM

Your comment:

 (will show your gravatar)