Reusability Of The Code With Three Layers Architecture In ASP.NET

When we think about a new project which is going to start, we first try to know which architecture will be useful and how to implement it with this project. So, architecture is the main concern before starting to develop new application. We divide our application into different tiers architecture or layers architecture, which helps developers to work easily with different components on the same time.

What we will learn with this article

  1. Three Tiers vs. Three Layers
  2. Details about Three Layers Architecture
  3. How to implement the Three Layers Architecture with ASP.NET

There are lots of misconception between developers that both 3 Tier Architecture and 3 Layers Architecture, are same. But this is not true and both are totally different to each other. So, first we need to know the difference between both and after that we will proceed with how to implement 3 Layers Architecture.

Three Tiers vs. Three Layers Architecture

Tier

Tier is basically a physical separation of the project components. It can be on different system or machine. Each tier has their own responsibility to perform their own task. For example, there is one tier which can get the data from database, so it can be some service or some APIs and it can also be on different machines or systems.

Other tier gets the data from first tier [services or APIs or some data access logic] and performs some business login on this and modifies the data before presenting to users.

And the other one or last tier can be used to show the data to user on UI.

So, this is not necessary that tier architecture must be 3 Tiers Architecture. It can be n-tiers architecture. Tiers Architecture is used when we are creating a broad range or enterprise application which has multiple module and using some third party service or APIs.


Tier

Layer

Layer is actually a logical separation of the component of the project. It has different layers like Data Access Layer, Business Access Layer and User Interface. You can also create some other layers as per your project requirement.

Details about Three Layers Architecture

As we have learned that layer architecture is basically a logical separation of the component on the same machine, so Three Layers Architecture has mainly 3 layers and these are Data Access Layer, Business Access Layer and Presentation Layer or User Interface.

Data Access Layer

It is the component of the architecture which has responsibility to handle data access logic. It stores the logic to access data from database or to add the data into the database. It contains all the logic to perform CRUD operation with database, xml or any other data source.

architecture

Business Access Layer

It is the component of the architecture where we define the business logic of the application. It is basically a bridge between Data Access Layer and Presentation Layer. So, responsibility of business access layer is that it performs some logic on the data which is coming from Data Access Layer and pass it to Presentation Layer.

Presentation Layer

It is nothing but only a user interface, which is used to show the data coming from business access layer. It is graphical user interface of the application which is used for interaction to users.

See the following image which will help you to understand the three layers architecture.

Data Access Layer

How to Implement the Three Layers Architecture with ASP.NET

So, the  time is to implement the actual code with ASP.NET application. We will go through one by one every layer and understand the code implementation.

Data Access Layer

Here we can add database connection logic, database CRUD operation activity like Insert, Update, Delete and Select with database. In this layer, we check the connection is open or not, how to manage database connection, how to get data from database and add data into database. We can also handle exception if any error occurred on the time of database activities performed.
  1. using System;  
  2. using System.Data;  
  3. using System.Data.Odbc;  
  4. using System.Configuration;  
  5.   
  6. /// <summary>  
  7. /// Summary description for DBAccess  
  8. /// </summary>  
  9. public class DBAccess  
  10. {  
  11.       
  12.     private OdbcCommand _objCommand = new OdbcCommand();  
  13.     private string strConnectionString = "";  
  14.   
  15.     public DBAccess()  
  16.     {  
  17.         OdbcConnection _objConnection = new OdbcConnection();  
  18.         ConnectionStringSettings  connectionString = ConfigurationManager.ConnectionStrings["connection"];  
  19.         strConnectionString = connectionString.ConnectionString;  
  20.         _objConnection.ConnectionString = strConnectionString;  
  21.         _objCommand.Connection = _objConnection;  
  22.   
  23.     }  
  24.     public string ConnectionString  
  25.     {  
  26.         get  
  27.         {  
  28.             return strConnectionString;  
  29.         }  
  30.         set  
  31.         {  
  32.             strConnectionString = value;  
  33.         }  
  34.     }  
  35.     private void Open()  
  36.     {  
  37.         _objCommand.Connection.Open();  
  38.     }  
  39.     private void Close()  
  40.     {  
  41.         _objCommand.Connection.Close();  
  42.     }  
  43.     public void Dispose()  
  44.     {  
  45.         _objCommand.Dispose();  
  46.     }  
  47.     public void AddParameters(string paramname, object paramvalue)  
  48.     {  
  49.         OdbcParameter param = new OdbcParameter(paramname, paramvalue);  
  50.         _objCommand.Parameters.Add(param);  
  51.     }  
  52.     public int Insert(string _commandText)  
  53.     {  
  54.         int i = -1;  
  55.         try  
  56.         {  
  57.             this.Open();  
  58.             _objCommand.CommandText = _commandText;  
  59.             i = _objCommand.ExecuteNonQuery();  
  60.   
  61.         }  
  62.         catch (Exception)  
  63.         {  
  64.             throw;  
  65.         }  
  66.         finally  
  67.         {  
  68.   
  69.             this.Close();  
  70.             this.Dispose();  
  71.         }  
  72.         return i;  
  73.     }  
  74.     public int returnSingleValue(string _commandText)  
  75.     {  
  76.         int i = -1;  
  77.         try  
  78.         {  
  79.             this.Open();  
  80.             _objCommand.CommandText = _commandText;  
  81.             i = Convert.ToInt32(_objCommand.ExecuteScalar());  
  82.         }  
  83.         catch (Exception)  
  84.         {  
  85.             throw;  
  86.         }  
  87.         finally  
  88.         {  
  89.             this.Close();  
  90.             this.Dispose();  
  91.         }  
  92.         return i;  
  93.     }  
  94.     public OdbcDataReader ExecuterReader(string _commandText)  
  95.     {  
  96.         OdbcDataReader _objDtReader = null;  
  97.         try  
  98.         {  
  99.             this.Open();  
  100.             _objCommand.CommandText = _commandText;  
  101.             _objDtReader = _objCommand.ExecuteReader(CommandBehavior.CloseConnection);  
  102.         }  
  103.         catch (Exception)  
  104.         {  
  105.             throw;  
  106.         }  
  107.         return _objDtReader;  
  108.     }  
  109.       
  110. }  
In the above code, we can see that data access logic has defined in that way, we don’t need to write any other code to perform database access logic [you can also write code for update and delete].

Business Access Layer

This layer performs all the business logic before passing the data to Presentation Layer. The data which is coming from Data Access Layer, might not be valid or user friendly, we need to modify the data before representing to user. So, the complete business logic performed inside the Business Access Layer.
  1. using System;  
  2. using System.Data;  
  3. using System.Data.Odbc;  
  4.   
  5. /// <summary>  
  6. /// Summary description for career  
  7. /// </summary>  
  8. public class career  
  9. {  
  10.     DBAccess db;  
  11.     OdbcDataReader _objDtReader = null;  
  12.     public career()  
  13.     {  
  14.         //  
  15.         // TODO: Add constructor logic here  
  16.         //  
  17.     }  
  18.     public long _careerID;  
  19.     private string _name;  
  20.     private string _firstName;  
  21.     private string _lastName;  
  22.     private string _emailID;  
  23.     private string _mobileNo;  
  24.     private string _dateOfBirth;  
  25.     private string _gender;  
  26.     private string _funcationalArea;  
  27.     private string _skills;  
  28.     private string _experience;  
  29.     private string _location;  
  30.     private string _resume;  
  31.     private int _jobID;  
  32.     private string _createdDate;  
  33.   
  34.     public long CareerID  
  35.     {  
  36.         get { return _careerID; }  
  37.         set { _careerID = value; }  
  38.     }  
  39.   
  40.     public string Name  
  41.     {  
  42.         get { return _name; }  
  43.         set { _name = value; }  
  44.     }  
  45.     public string FirstName  
  46.     {  
  47.         get { return _firstName; }  
  48.         set { _firstName = value;  }  
  49.     }  
  50.     public string LastName  
  51.     {  
  52.         get { return _lastName; }  
  53.         set { _lastName = value; }  
  54.     }  
  55.     public string EmailID  
  56.     {  
  57.         get { return _emailID; }  
  58.         set { _emailID = value; }  
  59.     }  
  60.     public string MobileNo  
  61.     {  
  62.         get { return _mobileNo; }  
  63.         set { _mobileNo = value; }  
  64.   
  65.     }  
  66.     public string DateOfBirth  
  67.     {  
  68.         get { return _dateOfBirth; }  
  69.         set { _dateOfBirth = value; }  
  70.     }  
  71.     public string Gender  
  72.     {  
  73.         get { return _gender; }  
  74.         set { _gender = value; }  
  75.   
  76.     }  
  77.     public string FunctionalArea  
  78.     {  
  79.         get { return _funcationalArea; }  
  80.         set { _funcationalArea = value; }  
  81.     }  
  82.     public string Skills  
  83.     {  
  84.         get { return _skills; }  
  85.         set { _skills = value; }  
  86.     }  
  87.     public string Experience  
  88.     {  
  89.         get { return _experience; }  
  90.         set { _experience = value; }  
  91.     }  
  92.     public string Locatin  
  93.     {  
  94.         get { return _location; }  
  95.         set { _location = value; }  
  96.     }  
  97.     public string Resume  
  98.     {  
  99.         get { return _resume; }  
  100.         set{_resume=value;}  
  101.     }  
  102.     public int JobID  
  103.     {  
  104.         get { return _jobID; }  
  105.         set { _jobID = value; }  
  106.     }  
  107.     public string CreatedDate  
  108.     {  
  109.         get { return _createdDate; }  
  110.         set { _createdDate = value; }  
  111.     }  
  112.   
  113.     public int addCareerDetailsByVisiter(career objClsCareer)  
  114.     {  
  115.          db = new DBAccess();  
  116.         int result = db.Insert("Call Insert_Career_Details('"+FirstName+"','"+LastName+"','"+EmailID+"','"+MobileNo+"','"+DateOfBirth+"','"+Gender+"','"+FunctionalArea+"','"+Skills+"','"+Experience+"','"+Locatin+"','"+Resume+"','"+JobID+"')");  
  117.         return result;  
  118.     }  
  119.     public DataTable viewAppliedJob(career objClsCareer)  
  120.     {  
  121.           
  122.         db = new DBAccess();  
  123.         DataTable _dt = new DataTable();  
  124.         _dt.Columns.Add("Career_ID");  
  125.         _dt.Columns.Add("Created_Date");  
  126.         _dt.Columns.Add("Name");  
  127.         _dt.Columns.Add("City");  
  128.         _dt.Columns.Add("Experience");  
  129.         _dt.Columns.Add("Functional_Area");  
  130.         _dt.Columns.Add("Mobile_No");  
  131.         _dt.Columns.Add("Resume");  
  132.   
  133.         _objDtReader = db.ExecuterReader("Call select_applied_job()");  
  134.         DataRow _dr = null;  
  135.         while (_objDtReader.Read())  
  136.         {  
  137.             _dr = _dt.NewRow();  
  138.             _dr["Career_ID"] = Convert.ToInt32(_objDtReader["career_id"]);  
  139.             _dr["Created_Date"] =Convert.ToDateTime(_objDtReader["created_date"]).ToString("dd/MMM/yy");  
  140.             _dr["Name"]=string.Concat(Convert.ToString(_objDtReader["first_name"]),"  ",Convert.ToString(_objDtReader["last_name"]));  
  141.             _dr["City"] = _objDtReader["city"];  
  142.             _dr["Experience"] = Convert.ToString(_objDtReader["Experience"]);  
  143.             _dr["Functional_Area"] = Convert.ToString(_objDtReader["functional_Area"]);  
  144.             _dr["mobile_no"] = _objDtReader["mobile_no"];  
  145.             _dr["resume"] ="../Resume/"+ Convert.ToString(_objDtReader["resume"]);  
  146.             _dt.Rows.Add(_dr);  
  147.   
  148.         } _objDtReader.Close();  
  149.         return _dt;  
  150.     }  
  151.   
  152.     public DataTable viewParticularAppliedJob(career objClsCareer)  
  153.     {  
  154.   
  155.         db = new DBAccess();  
  156.         DataTable _dt = new DataTable();  
  157.         _dt.Columns.Add("Career_ID");  
  158.         _dt.Columns.Add("Created_Date");  
  159.         _dt.Columns.Add("Job_Title");  
  160.         _dt.Columns.Add("Name");  
  161.         _dt.Columns.Add("City");  
  162.         _dt.Columns.Add("Experience");  
  163.         _dt.Columns.Add("Functional_Area");  
  164.         _dt.Columns.Add("Mobile_No");  
  165.         _dt.Columns.Add("Resume");  
  166.   
  167.         _objDtReader = db.ExecuterReader("Call select_applied_for_particular_job()");  
  168.         DataRow _dr = null;  
  169.         while (_objDtReader.Read())  
  170.         {  
  171.             _dr = _dt.NewRow();  
  172.             _dr["Career_ID"] = Convert.ToInt32(_objDtReader["career_id"]);  
  173.             _dr["Created_Date"] = Convert.ToDateTime(_objDtReader["created_date"]).ToString("dd/MMM/yy");  
  174.             _dr["Job_Title"] = Convert.ToString(_objDtReader["job_title"]);  
  175.             _dr["Name"] = string.Concat(Convert.ToString(_objDtReader["first_name"]), "  ", Convert.ToString(_objDtReader["last_name"]));  
  176.             _dr["City"] = _objDtReader["city"];  
  177.             _dr["Experience"] = Convert.ToString(_objDtReader["Experience"]);  
  178.             _dr["Functional_Area"] = Convert.ToString(_objDtReader["functional_Area"]);  
  179.             _dr["mobile_no"] = _objDtReader["mobile_no"];  
  180.             _dr["resume"] = "../Resume/" + Convert.ToString(_objDtReader["resume"]);  
  181.             _dt.Rows.Add(_dr);  
  182.   
  183.         } _objDtReader.Close();  
  184.         return _dt;  
  185.     }  
  186.     public static career getJobAppliedCareerProfile(long careerID)  
  187.     {  
  188.        DBAccess  db = new DBAccess();  
  189.        OdbcDataReader _objDtReader = null;  
  190.          _objDtReader = db.ExecuterReader("Call select_applied_job_career_profile('"+careerID+"')");  
  191.          if (_objDtReader.HasRows)  
  192.          {  
  193.              career objClsCareer = new career();  
  194.              while (_objDtReader.Read())  
  195.              {  
  196.                  objClsCareer.Name = string.Concat(Convert.ToString(_objDtReader["first_name"]), "  ", Convert.ToString(_objDtReader["last_name"]));  
  197.                  objClsCareer.EmailID = Convert.ToString(_objDtReader["email_id"]);  
  198.                  objClsCareer.MobileNo = Convert.ToString(_objDtReader["mobile_no"]);  
  199.                  objClsCareer.DateOfBirth = Convert.ToDateTime(_objDtReader["date_of_birth"]).ToString("dd-MMM-yyyy");  
  200.                  objClsCareer.Gender = Convert.ToString(_objDtReader["gender"]);  
  201.                  objClsCareer.FunctionalArea = Convert.ToString(_objDtReader["functional_area"]);  
  202.                  objClsCareer.Skills = Convert.ToString(_objDtReader["skills"]);  
  203.                  objClsCareer.Experience = Convert.ToString(_objDtReader["experience"]);  
  204.                  objClsCareer.Locatin = Convert.ToString(_objDtReader["city"]);  
  205.                  objClsCareer.Resume =Convert.ToString(_objDtReader["resume"]);  
  206.                  objClsCareer.CreatedDate = Convert.ToDateTime(_objDtReader["created_date"]).ToString("dd-MMM-yyyy");  
  207.              } _objDtReader.Close();  
  208.              return objClsCareer;  
  209.          }  
  210.          else  
  211.          {  
  212.              _objDtReader.Close();  
  213.              return new career();  
  214.          }  
  215.     }  
  216.     public DataTable getCurrentOpening()  
  217.     {  
  218.         db = new DBAccess();  
  219.         DataTable _dt = new DataTable();  
  220.         _dt.Columns.Add("job_id");  
  221.         _dt.Columns.Add("job_title");  
  222.         _dt.Columns.Add("experience");  
  223.         _dt.Columns.Add("location");  
  224.         _dt.Columns.Add("created_date");  
  225.         string varStatus="active";  
  226.         _objDtReader = db.ExecuterReader("Call select_current_opening('" + varStatus + "')");  
  227.         if (_objDtReader.HasRows)  
  228.         {  
  229.             DataRow _dr = null;  
  230.             while (_objDtReader.Read())  
  231.             {  
  232.                 _dr = _dt.NewRow();  
  233.                 _dr["job_id"] = Convert.ToInt32(_objDtReader["job_id"]);  
  234.                 _dr["job_title"] = Convert.ToString(_objDtReader["job_title"]);  
  235.                 _dr["experience"] = Convert.ToString(_objDtReader["experience"]);  
  236.                 _dr["location"] = Convert.ToString(_objDtReader["location"]);  
  237.                 _dr["created_date"] = Convert.ToDateTime(_objDtReader["created_date"]).ToString("dd-MMM-yyyy");  
  238.                 _dt.Rows.Add(_dr);  
  239.             } _objDtReader.Close();  
  240.             
  241.         }  
  242.         return _dt;  
  243.   
  244.          
  245.     }  
  246.   
  247. }  
Presentation Layer

It is only a user interface which represents the data to user. This layer is always visible to user. So, users can see the data and perform some access from here to pass the input logic. In ASP.NET, there are two files which participate in Presentation Layer, one is your design file[.aspx page] and second one is your code behind file [.aspx.cs page]

Data Access Object

CareerApply.aspx
  1. <%@ Page Language="C#" AutoEventWireup="true" CodeFile="CareerApply.aspx.cs" Inherits="View_CareerApply" %>  
  2.     <%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>  
  3.         <!DOCTYPE html>  
  4.         <html lang="en">  
  5.         <link rel="shortcut icon" href="../images/favicon.ico" />  
  6.   
  7.         <head runat="server">  
  8.             <title></title>  
  9.             <meta charset="utf-8">  
  10.             <link href="../css/reset.css" rel="stylesheet" />  
  11.             <link href="../css/style.css" rel="stylesheet" />  
  12.             <link href="../css/layout.css" rel="stylesheet" />  
  13.             <script src="../js/jquery-1.6.min.js"></script>  
  14.             <script src="../js/cufon-yui.js"></script>  
  15.             <script src="../js/cufon-replace.js"></script>  
  16.             <script src="../js/Open_Sans_400.font.js"></script>  
  17.             <script src="../js/Open_Sans_Light_300.font.js"></script>  
  18.             <script src="../js/Open_Sans_Semibold_600.font.js"></script>  
  19.             <script src="../js/tms-0.3.js"></script>  
  20.             <script src="../js/tms_presets.js"></script>  
  21.             <script src="../js/jquery.easing.1.3.js"></script>  
  22.             <script src="../js/FF-cash.js"></script>  
  23.             <script src="../js/validation.js"></script>  
  24.         </head>  
  25.   
  26.         <body id="page1">  
  27.             <!-- header -->  
  28.             <form id="form1" runat="server">  
  29.                 <asp:ScriptManager ID="ScriptManager1" runat="server"> </asp:ScriptManager>  
  30.                 <div class="bg">  
  31.                     <div class="main">  
  32.                         <header>  
  33.                             <div class="row-1">  
  34.                                 <h1>  
  35.   
  36. <a class="logo"></a>  
  37. </h1> </div>  
  38.                             <div class="row-2">  
  39.                                 <nav>  
  40.                                     <ul class="menu">  
  41.                                         <li><a href="../home.aspx">Home</a></li>  
  42.                                         <li><a href="aboutus.aspx">About Us</a></li>  
  43.                                         <li><a href="Product.aspx">Products</a></li>  
  44.                                         <li><a href="Value.aspx">Our Value</a></li>  
  45.                                         <li><a href="brand.aspx">Our Brand</a></li>  
  46.                                         <li><a class="active" href="CareerApply.aspx">Careers</a></li>  
  47.                                         <li class="last-item"><a href="contact.aspx">Contact Us</a></li>  
  48.                                     </ul>  
  49.                                 </nav>  
  50.                             </div>  
  51.                         </header>  
  52.                         <section id="content">  
  53.                             <div class="padding">  
  54.                                 <div class="wrapper">  
  55.                                     <div class="col-3">  
  56.                                         <div class="indent">  
  57.                                             <p class="color-4 p1"> </p>  
  58.                                             <div> <img src="../images/career.jpg" alt="Career with us" /> </div>  
  59.                                             <table style="width: 100%;">  
  60.                                                 <tr>  
  61.                                                     <td style="width: 120px; text-align: left;">First Name <span style="color: red;">*</span> </td>  
  62.                                                     <td>  
  63.                                                         <asp:TextBox runat="server" ID="txtFirstName" Width="100%" BorderColor="#ACC3DB" BorderWidth="1px" BorderStyle="Solid" onkeypress="return isCharacterKey(this,event);"></asp:TextBox>  
  64.                                                     </td>  
  65.                                                 </tr>  
  66.                                                 <tr>  
  67.                                                     <td style="width: 30px; text-align: left;"></td>  
  68.                                                     <td>  
  69.                                                         <asp:RequiredFieldValidator runat="server" ID="reqName" ControlToValidate="txtFirstName" ErrorMessage="First Name Required" Font-Names="Sans-Sarif" ForeColor="#BF19D5" EnableClientScript="true"></asp:RequiredFieldValidator>  
  70.                                                         <br /> </td>  
  71.                                                 </tr>  
  72.                                                 <tr>  
  73.                                                     <td style="width: 30px; text-align: left;">Last Name  
  74.                                                         <br />  
  75.                                                         <br /> </td>  
  76.                                                     <td>  
  77.                                                         <asp:TextBox runat="server" ID="txtLastName" Width="100%" BorderColor="#ACC3DB" BorderWidth="1px" BorderStyle="Solid" onkeypress="return isCharacterKey(this,event);"></asp:TextBox>  
  78.                                                         <br />  
  79.                                                         <br /> </td>  
  80.                                                 </tr>  
  81.                                                 <tr>  
  82.                                                     <td style="width: 30px; text-align: left;">Email ID<span style="color: red;">*</span> </td>  
  83.                                                     <td>  
  84.                                                         <asp:TextBox runat="server" ID="txtEmailID" Width="100%" BorderColor="#ACC3DB" BorderWidth="1px" BorderStyle="Solid"></asp:TextBox>  
  85.                                                     </td>  
  86.                                                 </tr>  
  87.                                                 <tr>  
  88.                                                     <td style="width: 30px; text-align: left;"></td>  
  89.                                                     <td>  
  90.                                                         <asp:RequiredFieldValidator runat="server" ID="RequiredFieldValidator1" Display="Dynamic" ControlToValidate="txtEmailID" ErrorMessage="Email ID Required" Font-Names="Sans-Sarif" ForeColor="#BF19D5"></asp:RequiredFieldValidator>  
  91.                                                         <br />  
  92.                                                         <asp:RegularExpressionValidator ID="regE_1" Display="Dynamic" runat="server" ErrorMessage="You must enter valid email address" ControlToValidate="txtEmailID" ForeColor="#BF19D5" ValidationExpression="^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$"> </asp:RegularExpressionValidator>  
  93.                                                     </td>  
  94.                                                 </tr>  
  95.                                                 <tr>  
  96.                                                     <td style="width: 30px; text-align: left;">Mobile No<span style="color: red;">*</span> </td>  
  97.                                                     <td>  
  98.                                                         <asp:TextBox runat="server" ID="txtMobileNo" Width="20%" MaxLength="10" BorderColor="#ACC3DB" BorderWidth="1px" BorderStyle="Solid" onkeypress="return isNum_Hyph(this,event);"></asp:TextBox>  
  99.                                                     </td>  
  100.                                                 </tr>  
  101.                                                 <tr>  
  102.                                                     <td style="width: 30px; text-align: left;">  
  103.                                                         <br /> </td>  
  104.                                                     <td>  
  105.                                                         <asp:RequiredFieldValidator runat="server" ID="RequiredFieldValidator5" Display="Dynamic" ControlToValidate="txtMobileNo" ErrorMessage="Mobile No Required" Font-Names="Sans-Sarif" ForeColor="#BF19D5"></asp:RequiredFieldValidator>  
  106.                                                         <br /> </td>  
  107.                                                 </tr>  
  108.                                                 <tr>  
  109.                                                     <td style="width: 30px; text-align: left;">Date of Birth<span style="color: red;">*</span> </td>  
  110.                                                     <td>  
  111.                                                         <asp:TextBox runat="server" ID="txtDateOfBirth" Width="25%" BorderColor="#ACC3DB" BorderWidth="1px" BorderStyle="Solid" ValidationGroup="cal_1"></asp:TextBox>  
  112.                                                         <asp:ImageButton runat="server" ID="ibtnDOB" ImageUrl="~/images/calendar_icon.png" Width="30px" Height="25px" ImageAlign="AbsBottom" ValidationGroup="cal_2" />  
  113.                                                         <cc1:CalendarExtender runat="server" ID="Calendar1" TargetControlID="txtDateOfBirth" PopupButtonID="ibtnDOB" Animated="true" EnabledOnClient="true" EnableViewState="false" Format="dd/MMM/yyyy"> </cc1:CalendarExtender>  
  114.                                                     </td>  
  115.                                                 </tr>  
  116.                                                 <tr>  
  117.                                                     <td style="width: 30px; text-align: left;">  
  118.                                                         <br /> </td>  
  119.                                                     <td>  
  120.                                                         <asp:RequiredFieldValidator runat="server" ID="RequiredFieldValidator4" Display="Dynamic" ControlToValidate="txtDateOfBirth" ErrorMessage="Date of Birth Required" Font-Names="Sans-Sarif" ForeColor="#BF19D5"></asp:RequiredFieldValidator>  
  121.                                                         <br /> </td>  
  122.                                                 </tr>  
  123.                                                 <tr>  
  124.                                                     <td style="width: 30px; text-align: left;">Gender  
  125.                                                         <br />  
  126.                                                         <br /> </td>  
  127.                                                     <td>  
  128.                                                         <asp:RadioButton runat="server" ID="rdbMale" GroupName="gender" Text="Male" />  
  129.                                                         <asp:RadioButton runat="server" ID="rdbFemale" GroupName="gender" Text="FeMale" />  
  130.                                                         <br />  
  131.                                                         <br /> </td>  
  132.                                                 </tr>  
  133.                                                 <tr>  
  134.                                                     <td style="width: 30px; text-align: left;">Functional Area<span style="color: red;">*</span> </td>  
  135.                                                     <td>  
  136.                                                         <asp:TextBox runat="server" ID="txtFunctionalArea" Width="100%" BorderColor="#ACC3DB" BorderWidth="1px" BorderStyle="Solid" MaxLength="255"></asp:TextBox>  
  137.                                                     </td>  
  138.                                                 </tr>  
  139.                                                 <tr>  
  140.                                                     <td style="width: 30px; text-align: left;">  
  141.                                                         <br /> </td>  
  142.                                                     <td>  
  143.                                                         <asp:RequiredFieldValidator runat="server" ID="RequiredFieldValidator6" Display="Dynamic" ControlToValidate="txtFunctionalArea" ErrorMessage="Functional Area Required!" Font-Names="Sans-Sarif" ForeColor="#BF19D5"></asp:RequiredFieldValidator>  
  144.                                                         <br /> </td>  
  145.                                                 </tr>  
  146.                                                 <tr>  
  147.                                                     <td style="width: 30px; text-align: left;">Skill Details  
  148.                                                         <br />  
  149.                                                         <br /> </td>  
  150.                                                     <td>  
  151.                                                         <asp:TextBox runat="server" ID="txtSkillDetail" TextMode="MultiLine" Width="100%" BorderColor="#ACC3DB" BorderWidth="1px" BorderStyle="Solid" ValidationGroup="cal_1"></asp:TextBox>  
  152.                                                         <br />  
  153.                                                         <br /> </td>  
  154.                                                 </tr>  
  155.                                                 <tr>  
  156.                                                     <td style="width: 30px; text-align: left;">Experience<span style="color: red;">*</span> </td>  
  157.                                                     <td>  
  158.                                                         <asp:DropDownList runat="server" ID="ddlExperience" onselectedindexchanged="ddlExperience_SelectedIndexChanged" AutoPostBack="True">  
  159.                                                             <asp:ListItem Enabled="true" Selected="True" Text="select" Value="0"></asp:ListItem>  
  160.                                                             <asp:ListItem Text="Fresher" Value="1"></asp:ListItem>  
  161.                                                             <asp:ListItem Text="Experienced" Value="2"></asp:ListItem>  
  162.                                                         </asp:DropDownList>  
  163.                                                         <asp:UpdatePanel runat="server" ID="upnlExperiece">  
  164.                                                             <ContentTemplate>  
  165.                                                                 <asp:Label runat="server" ID="lblExperience" Visible="false"></asp:Label>  
  166.                                                                 <asp:TextBox runat="server" ID="txtExperience" Width="50%" BorderColor="#ACC3DB" BorderWidth="1px" BorderStyle="Solid" Visible="false"></asp:TextBox>  
  167.                                                                 <br />  
  168.                                                                 <asp:RequiredFieldValidator runat="server" ID="RequiredFieldValidator8" Display="Dynamic" ControlToValidate="txtExperience" ErrorMessage="Fill Experience Value!" Font-Names="Sans-Sarif" ForeColor="#BF19D5"></asp:RequiredFieldValidator>  
  169.                                                             </ContentTemplate>  
  170.                                                             <Triggers>  
  171.                                                                 <asp:AsyncPostBackTrigger ControlID="ddlExperience" EventName="SelectedIndexChanged" /> </Triggers>  
  172.                                                         </asp:UpdatePanel>  
  173.                                                     </td>  
  174.                                                 </tr>  
  175.                                                 <tr>  
  176.                                                     <td style="width: 30px; text-align: left;">  
  177.                                                         <br /> </td>  
  178.                                                     <td>  
  179.                                                         <asp:RequiredFieldValidator runat="server" ID="RequiredFieldValidator7" Display="Dynamic" ControlToValidate="ddlExperience" ErrorMessage="Experience Required!" InitialValue="0" Font-Names="Sans-Sarif" ForeColor="#BF19D5"></asp:RequiredFieldValidator>  
  180.                                                         <br /> </td>  
  181.                                                 </tr>  
  182.                                                 <tr>  
  183.                                                     <td style="width: 30px; text-align: left;">Current Location<span style="color: red;">*</span> </td>  
  184.                                                     <td>  
  185.                                                         <asp:TextBox runat="server" ID="txtCity" Width="100%" BorderColor="#ACC3DB" BorderWidth="1px" BorderStyle="Solid" MaxLength="255"></asp:TextBox>  
  186.                                                     </td>  
  187.                                                 </tr>  
  188.                                                 <tr>  
  189.                                                     <td style="width: 30px; text-align: left;">  
  190.                                                         <br /> </td>  
  191.                                                     <td>  
  192.                                                         <asp:RequiredFieldValidator runat="server" ID="RequiredFieldValidator9" Display="Dynamic" ControlToValidate="txtCity" ErrorMessage="Current Location Required!" Font-Names="Sans-Sarif" ForeColor="#BF19D5"></asp:RequiredFieldValidator>  
  193.                                                         <br /> </td>  
  194.                                                 </tr>  
  195.                                                 <tr>  
  196.                                                     <td style="width: 30px; text-align: left;">Upload Resume<span style="color: red;">*</span>  
  197.                                                         <br />  
  198.                                                         <br /> </td>  
  199.                                                     <td>  
  200.                                                         <asp:FileUpload runat="server" ID="fupResume" />  
  201.                                                         <br />  
  202.                                                         <asp:RegularExpressionValidator runat="server" ID="rex1" ControlToValidate="fupResume" Display="Dynamic" EnableClientScript="true" EnableViewState="false" ErrorMessage="Only doc file allowed" SetFocusOnError="true" ToolTip="Only doc file allowed " TabIndex="1" ValidationExpression="^.*?\.(doc|docx)$"></asp:RegularExpressionValidator>  
  203.                                                         <br />  
  204.                                                         <asp:RequiredFieldValidator runat="server" ID="RequiredFieldValidator3" ControlToValidate="fupResume" ErrorMessage="Upload Your Updated Resume" Font-Names="Sans-Sarif" ForeColor="#BF19D5"></asp:RequiredFieldValidator>  
  205.                                                         <br /> </td>  
  206.                                                 </tr>  
  207.                                                 <tr>  
  208.                                                     <td style="width: 30px; text-align: left;">  
  209.                                                         <br />  
  210.                                                         <br /> </td>  
  211.                                                     <td>  
  212.                                                         <asp:Image ID="Image1" runat="server" ImageUrl="~/View/CImage.aspx" />  
  213.                                                         <br />  
  214.                                                         <br /> </td>  
  215.                                                 </tr>  
  216.                                                 <tr>  
  217.                                                     <td style="width: 30px; text-align: left;">Security Text<span style="color: red;">*</span> </td>  
  218.                                                     <td>  
  219.                                                         <div> </div>  
  220.                                                         <asp:TextBox ID="txtimgcode" runat="server" BorderColor="#ACC3DB" BorderWidth="1px" BorderStyle="Solid"></asp:TextBox>  
  221.                                                         <br /> <span style="font-family:sans-serif; font-size:x-small;">Enter the characters shown in the image.</span>  
  222.                                                         <asp:Label ID="lblmsg" runat="server" Font-Bold="false" ForeColor="Red" Text=""></asp:Label>  
  223.                                                     </td>  
  224.                                                 </tr>  
  225.                                                 <tr>  
  226.                                                     <td style="width: 30px; text-align: left;"></td>  
  227.                                                     <td>  
  228.                                                         <asp:RequiredFieldValidator runat="server" ID="RequiredFieldValidator2" ControlToValidate="txtimgcode" ErrorMessage="Fill Image Code" Font-Names="Sans-Sarif" ForeColor="#BF19D5"></asp:RequiredFieldValidator>  
  229.                                                         <br /> </td>  
  230.                                                 </tr>  
  231.                                                 <tr>  
  232.                                                     <td style="width: 30px;">  
  233.                                                         <br />  
  234.                                                         <br /> </td>  
  235.                                                     <td style="text-align: center;">  
  236.                                                         <asp:Button runat="server" ID="btnSubmit" Text="Submit" OnClick="btnSubmit_Click" />  
  237.                                                         <br />  
  238.                                                         <br /> </td>  
  239.                                                 </tr>  
  240.                                             </table>  
  241.                                         </div>  
  242.                                     </div>  
  243.                                     <div class="col-2">  
  244.                                         <div class="block-news">  
  245.                                             <h4 class="color-4 p2">Current Opening</h4>  
  246.                                             <asp:Repeater runat="server" ID="repCurrentOpening">  
  247.                                                 <ItemTemplate>  
  248.                                                     <table style="width:100%;" border="1">  
  249.                                                         <tr>  
  250.                                                             <td colspan="3">  
  251.                                                                 <hr style="border: 1px dashed #CACACA;" /> </td>  
  252.                                                         </tr>  
  253.                                                         <tr>  
  254.                                                             <td colspan="3"> <a href="ViewCurrentOpeningJob.aspx?job=<%# Eval(" job_id ") %>" style="text-decoration:none;"><span style="color:#E931C1; font-size:medium; "><%# Eval("job_title") %></span></a>  
  255.                                                                 <br />  
  256.                                                                 <br /> </td>  
  257.                                                         </tr>  
  258.                                                         <tr>  
  259.                                                             <td style="color:#1491C6; font-size:small; font-weight:bold; width:80px;"> Location </td>  
  260.                                                             <td style="width:2px;"> : </td>  
  261.                                                             <td style="color:#1491C6; font-size:smaller; padding-left:5px; ">  
  262.                                                                 <%# Eval("location") %>  
  263.                                                             </td>  
  264.                                                         </tr>  
  265.                                                         <tr>  
  266.                                                             <td style="color:#1491C6; font-size:small; font-weight:bold; width:80px;"> Experience </td>  
  267.                                                             <td style="width:2px;"> : </td>  
  268.                                                             <td style="color:#1491C6; font-size:smaller; padding-left:5px; ">  
  269.                                                                 <%# Eval("experience") %>  
  270.                                                             </td>  
  271.                                                         </tr>  
  272.                                                         <tr>  
  273.                                                             <td style="color:#1491C6; font-size:small; font-weight:bold; width:80px;"> Posted Date </td>  
  274.                                                             <td style="width:2px;"> : </td>  
  275.                                                             <td style="color:#1491C6; font-size:smaller; padding-left:5px; ">  
  276.                                                                 <%# Eval("created_date") %>  
  277.                                                             </td>  
  278.                                                         </tr>  
  279.                                                     </table>  
  280.                                                 </ItemTemplate>  
  281.                                             </asp:Repeater>  
  282.                                         </div>  
  283.                                     </div>  
  284.                                 </div>  
  285.                             </div>  
  286.                         </section>  
  287.                     </div>  
  288.                 </div>  
  289.                 <script type="text/javascript">  
  290.                 Cufon.now();  
  291.                 </script>  
  292.                 <script type="text/javascript">  
  293.                 $(function ()  
  294.                 {  
  295.                     $('.slider')  
  296.                         ._TMS(  
  297.                         {  
  298.                             prevBu: '.prev',  
  299.                             nextBu: '.next',  
  300.                             playBu: '.play',  
  301.                             duration: 800,  
  302.                             easing: 'easeOutQuad',  
  303.                             preset: 'simpleFade',  
  304.                             pagination: false,  
  305.                             slideshow: 3000,  
  306.                             numStatus: false,  
  307.                             pauseOnHover: true,  
  308.                             banners: true,  
  309.                             waitBannerAnimation: false,  
  310.                             bannerShow: function (banner)  
  311.                             {  
  312.                                 banner.hide()  
  313.                                     .fadeIn(500)  
  314.                             },  
  315.                             bannerHide: function (banner)  
  316.                             {  
  317.                                 banner.show()  
  318.                                     .fadeOut(500)  
  319.                             }  
  320.                         });  
  321.                 })  
  322.                 </script>  
  323.             </form>  
  324.         </body>  
  325.   
  326.   </html>  
CareerApply.aspx.cs
  1. using System;  
  2. using System.IO;  
  3. using System.Data;  
  4. public partial class View_CareerApply: System.Web.UI.Page  
  5. {  
  6.     string varResumeName, varExperiece;  
  7.     protected void Page_Load(object sender, EventArgs e)  
  8.     {  
  9.         if(!IsPostBack)  
  10.         {  
  11.             this.txtFirstName.Focus();  
  12.             getCurrentOpening();  
  13.         }  
  14.     }  
  15.     protected void btnSubmit_Click(object sender, EventArgs e)  
  16.     {  
  17.         if(this.txtimgcode.Text == this.Session["CaptchaImageText"].ToString())  
  18.         {  
  19.             career objClsCareer = new career();  
  20.             objClsCareer.FirstName = txtFirstName.Text;  
  21.             objClsCareer.LastName = txtLastName.Text;  
  22.             objClsCareer.EmailID = txtEmailID.Text;  
  23.             objClsCareer.MobileNo = txtMobileNo.Text;  
  24.             objClsCareer.DateOfBirth = Convert.ToDateTime(txtDateOfBirth.Text)  
  25.                 .ToString("yyyy-MM-dd");  
  26.             if(rdbMale.Checked == true)  
  27.             {  
  28.                 objClsCareer.Gender = "Male";  
  29.             }  
  30.             else if(rdbFemale.Checked == true)  
  31.             {  
  32.                 objClsCareer.Gender = "Female";  
  33.             }  
  34.             else  
  35.             {  
  36.                 objClsCareer.Gender = "";  
  37.             }  
  38.             objClsCareer.FunctionalArea = txtFunctionalArea.Text;  
  39.             objClsCareer.Skills = txtSkillDetail.Text;  
  40.             if(Convert.ToString(txtExperience.Text)  
  41.                 .Equals(""))  
  42.             {  
  43.                 varExperiece = "fresher";  
  44.             }  
  45.             else  
  46.             {  
  47.                 varExperiece = txtExperience.Text;  
  48.             }  
  49.             objClsCareer.Experience = varExperiece;  
  50.             objClsCareer.Locatin = txtCity.Text;  
  51.             if(fupResume.HasFile)  
  52.             {  
  53.                 varResumeName = "Resume_" + DateTime.Now.ToString("ddMMMyyyy") + DateTime.Now.Hour + DateTime.Now.Minute + Path.GetFileName(fupResume.PostedFile.FileName);  
  54.                 fupResume.SaveAs(Server.MapPath("~/Resume/" + varResumeName));  
  55.                 objClsCareer.Resume = varResumeName;  
  56.             }  
  57.             objClsCareer.JobID = 0;  
  58.             int result = objClsCareer.addCareerDetailsByVisiter(objClsCareer);  
  59.             if(result > 0)  
  60.             {  
  61.                 Response.Write("<script language='javascript'>alert('Thank you! We will contact with you very soon'); window.location.href='../home.aspx'</script>");  
  62.             }  
  63.         }  
  64.         else  
  65.         {  
  66.             lblmsg.Text = "image code is not valid.";  
  67.         }  
  68.         this.txtimgcode.Text = "";  
  69.     }  
  70.     public void getCurrentOpening()  
  71.     {  
  72.         career objClsCareer = new career();  
  73.         DataTable dt = new DataTable();  
  74.         dt = objClsCareer.getCurrentOpening();  
  75.         if(dt.Rows.Count > 0)  
  76.         {  
  77.             repCurrentOpening.DataSource = dt;  
  78.             repCurrentOpening.DataBind();  
  79.         }  
  80.         else  
  81.         {}  
  82.     }  
  83.     protected void ddlExperience_SelectedIndexChanged(object sender, EventArgs e)  
  84.     {  
  85.         if(Convert.ToInt32(ddlExperience.SelectedValue) == 2)  
  86.         {  
  87.             // txtExperience.Text = "";  
  88.             lblExperience.Visible = true;  
  89.             lblExperience.Text = "Enter Experience Here";  
  90.             txtExperience.Visible = true;  
  91.         }  
  92.         else  
  93.         {  
  94.             lblExperience.Visible = false;  
  95.             txtExperience.Visible = false;  
  96.             //txtExperience.Text = "Experience";  
  97.         }  
  98.     }  
  99. }  
I hope this article will help beginners as well as experience developers to understand the three layers architecture who has not worked on this.