Registration form Using 3 tier architecture in C#

Step 1 : Create User registration form using Master page,
  1. <asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server"></asp:Content>  
  2. <asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">  
  3.     <div>  
  4.         <asp:Table ID="Table1" runat="server" >  
  5.             <asp:TableRow>  
  6.                 <asp:TableCell>Full Name</asp:TableCell>  
  7.                 <asp:TableCell>  
  8.                     <asp:TextBox ID="txtName" runat="server" ></asp:TextBox>  
  9.                 </asp:TableCell>  
  10.             </asp:TableRow>  
  11.             <asp:TableRow>  
  12.                 <asp:TableCell>User Name</asp:TableCell>  
  13.                 <asp:TableCell>  
  14.                     <asp:TextBox ID="txtUserName" runat="server" ></asp:TextBox>  
  15.                 </asp:TableCell>  
  16.             </asp:TableRow>  
  17.             <asp:TableRow>  
  18.                 <asp:TableCell>Password</asp:TableCell>  
  19.                 <asp:TableCell>  
  20.                     <asp:TextBox ID="txtpassword" runat="server" TextMode="Password" ></asp:TextBox>  
  21.                 </asp:TableCell>  
  22.             </asp:TableRow>  
  23.             <asp:TableRow>  
  24.                 <asp:TableCell> Email ID </asp:TableCell>  
  25.                 <asp:TableCell>  
  26.                     <asp:TextBox ID="txtEmailid" runat="server" ></asp:TextBox>  
  27.                 </asp:TableCell>  
  28.             </asp:TableRow>  
  29.             <asp:TableRow>  
  30.                 <asp:TableCell>Contact No</asp:TableCell>  
  31.                 <asp:TableCell>  
  32.                     <asp:TextBox ID="txtContact" runat="server" ></asp:TextBox>  
  33.                 </asp:TableCell>  
  34.             </asp:TableRow>  
  35.             <asp:TableRow>  
  36.                 <asp:TableCell>City</asp:TableCell>  
  37.                 <asp:TableCell>  
  38.                     <asp:TextBox ID="txtcity" runat="server" ></asp:TextBox>  
  39.                 </asp:TableCell>  
  40.             </asp:TableRow>  
  41.             <asp:TableRow>  
  42.                 <asp:TableCell>Area code</asp:TableCell>  
  43.                 <asp:TableCell>  
  44.                     <asp:TextBox ID="txtAreaCode" runat="server" ></asp:TextBox>  
  45.                 </asp:TableCell>  
  46.             </asp:TableRow>  
  47.             <asp:TableRow>  
  48.                 <asp:TableCell>UserRole</asp:TableCell>  
  49.                 <asp:TableCell>  
  50.                     <asp:DropDownList runat="server" ID="ddlUserRole"></asp:DropDownList>  
  51.                 </asp:TableCell>  
  52.             </asp:TableRow>  
  53.             <asp:TableRow>  
  54.                 <asp:TableCell></asp:TableCell>  
  55.                 <asp:TableCell>  
  56.                     <asp:Button ID="btnSave" runat="server" onclick="btnSave_Click" Text="Submit Data" />  
  57.                 </asp:TableCell>  
  58.             </asp:TableRow>  
  59.         </asp:Table>  
  60.     </div>  
  61. </asp:Content>  
Step 2 : Now Create User registration form DAL Class File.
  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.Linq;  
  4. using System.Web;  
  5. using System.Data;  
  6. using System.Data.Sql;  
  7. using System.Data.SqlClient;  
  8. using System.Text;  
  9. using System.Configuration;  
  10.   
  11. namespace Real_Estate.DAL   
  12. {  
  13.     public class DAL_NewUserEntrys  
  14.     {  
  15.         string connString = ConfigurationManager.ConnectionStrings["connstr"].ConnectionString;  
  16.         public int InsertNewUser(string U_FullName, string U_Name, string U_Email, string U_Contact, string U_Password, string U_City, string U_Area_Code, int UR_id, DateTime U_CreateDate)   
  17.         {  
  18.             var returnData = 0;  
  19.             using(SqlConnection con = new SqlConnection(connString))  
  20.             {  
  21.                 using(SqlCommand cmd = new SqlCommand("sp_NewUser", con))   
  22.                 {  
  23.                     cmd.CommandType = CommandType.StoredProcedure;  
  24.                     SqlParameter[] perm = new SqlParameter[9];  
  25.                     perm[0] = new SqlParameter("@U_FullName", SqlDbType.NVarChar, 50);  
  26.                     perm[0].Value = U_FullName;  
  27.                     perm[1] = new SqlParameter("@U_Name", SqlDbType.NVarChar, 30);  
  28.                     perm[1].Value = U_Name;  
  29.                     perm[2] = new SqlParameter("@U_Email", SqlDbType.NVarChar, 50);  
  30.                     perm[2].Value = U_Email;  
  31.                     perm[3] = new SqlParameter("@U_Contact", SqlDbType.NVarChar, 15);  
  32.                     perm[3].Value = U_Contact;  
  33.                     perm[4] = new SqlParameter("@U_Password", SqlDbType.NVarChar, 20);  
  34.                     perm[4].Value = U_Password;  
  35.                     perm[5] = new SqlParameter("@U_City", SqlDbType.NVarChar, 25);  
  36.                     perm[5].Value = U_City;  
  37.                     perm[6] = new SqlParameter("@U_Area_P_Code", SqlDbType.NVarChar, 10);  
  38.                     perm[6].Value = U_Area_Code;  
  39.                     perm[7] = new SqlParameter("@UR_id", SqlDbType.Int);  
  40.                     perm[7].Value = UR_id;  
  41.                     perm[8] = new SqlParameter("@U_CreateDate", SqlDbType.DateTime.ToString());  
  42.                     perm[8].Value = U_CreateDate;  
  43.                     cmd.Parameters.AddRange(perm);  
  44.                     con.Open();  
  45.                     returnData = cmd.ExecuteNonQuery();  
  46.                     con.Close();  
  47.                     con.Dispose();  
  48.                 }  
  49.             }  
  50.             return returnData;  
  51.         }  
  52.     }  
  53. }   
Step 3Now Create User registration form BAL Class File.
  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.Linq;  
  4. using System.Web;  
  5. using System.Text;  
  6. using Real_Estate.DAL;  
  7.   
  8. namespace Real_Estate.BAL  
  9. {  
  10.     public class BAL_NewUserEntry   
  11.     {  
  12.         public int InsertNewUser(string U_FullName, string U_Name, string U_Email, string U_Contact, string U_Password, string U_City, string U_Area_Code, int UR_id, DateTime U_CreateDate) {  
  13.             return new DAL_NewUserEntrys().InsertNewUser(U_FullName, U_Name, U_Email, U_Contact, U_Password, U_City, U_Area_Code, UR_id, U_CreateDate);  
  14.         }  
  15.     }  
  16. }   
Step 4 : Finally write submit button code on aspx.cs page.
  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.Linq;  
  4. using System.Web;  
  5. using System.Web.UI;  
  6. using System.Web.UI.WebControls;  
  7. using System.Data;  
  8. using System.Data.SqlClient;  
  9. using System.Configuration;  
  10. using Real_Estate.BAL;  
  11.   
  12. namespace Real_Estate.Form  
  13. {  
  14.     public partial class UserRegistration: System.Web.UI.Page  
  15.     {  
  16.         string connection = ConfigurationManager.ConnectionStrings["connstr"].ConnectionString;  
  17.         protected void Page_Load(object sender, EventArgs e)   
  18.         {  
  19.             if (!IsPostBack)   
  20.             {  
  21.                 BindUserRole();  
  22.             }  
  23.         }  
  24.         protected void BindUserRole() // Bind Dropdownlist form database  
  25.         {  
  26.             using(SqlConnection conn = new SqlConnection(connection))  
  27.             {  
  28.                 conn.Open();  
  29.                 SqlCommand cmd = new SqlCommand("sp_UserRole", conn);  
  30.                 cmd.CommandType = System.Data.CommandType.StoredProcedure;  
  31.                 SqlDataAdapter da = new SqlDataAdapter(cmd);  
  32.                 DataSet dt = new DataSet();  
  33.                 da.Fill(dt);  
  34.                 ddlUserRole.DataSource = dt;  
  35.                 ddlUserRole.DataTextField = "UR_Role";  
  36.                 ddlUserRole.DataValueField = "UR_id";  
  37.                 ddlUserRole.DataBind();  
  38.                 conn.Close();  
  39.             }  
  40.         }  
  41.         protected void btnSave_Click(object sender, EventArgs e) {  
  42.             var result = 0;  
  43.             int UR_id = 0;  
  44.             int.TryParse(ddlUserRole.SelectedValue, out UR_id);  
  45.             DateTime U_CeateDate = DateTime.Now;  
  46.             result = new BAL_NewUserEntry().InsertNewUser(txtName.Text.Trim(), txtUserName.Text.Trim(), txtEmailid.Text.Trim(), txtContact.Text.Trim(), txtpassword.Text.Trim(), txtcity.Text.Trim(), txtAreaCode.Text.Trim(), UR_id, U_CeateDate);  
  47.         }  
  48.     }  
  49. }  
Note: Here set connection string in web.config
  1. <configuration>  
  2.     <connectionStrings>  
  3.         <add name="connstr"  
  4. connectionString="Data Source=RAKESH-PC;Initial Catalog=Real_Estate;User ID=sa;Password=****" providerName="System.Data.SqlClient" />  
  5.     </connectionStrings>  
Also Create stored procedure in your database 
 
Screen Shoot :