Knowledge Walls
Gopal Rao
Mumbai, Maharashtra, India
Passcode:
Creating a simple registration form / sign up in asp.net using c#
126157 Views
Look of Registration Form 
BalRegister.cs
	using System;
	using System.Collections.Generic;
	using System.Linq;
	using System.Text;
	using BO;
	using DAL;
	
	namespace BAL
	{
	   public class balRegister
	   {
	       dalRegister dalregister = new dalRegister();
	       public int balreg(boRegister boregister)
	       {
	           try
	           {
	               return dalregister.dalreg(boregister);
	           }
	           catch (Exception ex)
	           {
	               ex.GetType();
	            }
	           return 0;
	       }
	   }
	}
DalRegister.cs
	using System;
	using System.Collections.Generic;
	using System.Linq;
	using System.Text;
	using System.Data;
	using System.Data.SqlClient;
	using BO;
	
	namespace DAL
	{
	   public class dalRegister
	   {
	       SqlConnection conn = new SqlConnection(@"data source=LAKSHANYA\SQLEXPRESS;database=master;integrated security=true");
	       public int dalreg(boRegister boregister)
	       {
	           try
	           {
	               conn.Open();
	               SqlCommand cmd = new SqlCommand("insert into user_table values('" + boregister.userName + "','" + boregister.gender + "','" + boregister.password + "','" + boregister.cPassword + "','" + boregister.fees + "','" + boregister.userType + "','" + boregister.eMail + "')", conn);
	               cmd.ExecuteNonQuery();
	               return 1;
	           }
	           catch (Exception ex)
	           {
	               throw ex;
	           }
	           finally
	           {
	               conn.Close();
	           }
	       }
	   }
	}
Register Preview 
Value inserted in table 
Conclusion 
I think my lesson helps you to make registration page in asp.net.
Introduction 
In this lesson i made one registration form in asp.net.I have created this in three tier architecture.
What i have done in this:
  1. Getting six values from the user.
  2. Validating the user inputs for all the aspects with asp controls validators.
  3. Checking whether the user name is available or not in datadase.If the user name already present in DB showing the message "User Name Not Available.Try With Different User Name".
  4. If user name is available, inserting the user inputs in DB table and showing message "Registered Successfully".
ASP controls validations 

Without filling the data, if you click the sign up button, form shows the message to fill the datas.
Asp validations for password and email. 
If the Paasword and confirm password not matched it shows message passwords are not matched.If the email not in correct format it shows message.
Class Libraries  
Note : Dont forget to refer the class library.Because i have done this in 3 layer architecture


Inside BAL class library i have created class named balRegister.cs
Inside BO class library i have created class named boRegister.cs
Inside DAL class library i have created class named dalRegister.cs
Inside cdManage application i have created web form named Home.aspx
Below i gave code for all the classes and web form.
Create table in Sql
	create table user_table(
	userName varchar(20),
	gender varchar(20),
	password varchar(20),
	cpassword varchar(20),
	fees varchar(20),
	userType varchar(20),
	email varchar(50))
Home.aspx
	<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd
	<html xmlns="http://www.w3.org/1999/xhtml">
	<head runat="server">
	  <title></title>
	  <link href="~/Styles/Site.css" rel="stylesheet" type="text/css" />
	  <style type="text/css">
	      .style1
	      {
	          width: 436px;
	          text-align: center;
	          height: 45px;
	      }
	      .style2
	      {
	          color: #0066CC;
	          text-align: center;
	      }
	      .style7
	      {
	          height: 45px;
	          color: #0066CC;
	          text-align: left;
	      }
	      .style8
	      {
	          height: 45px;
	          color: #0066CC;
	          text-align: center;
	      }
	      .style9
	      {
	          height: 45px;
	          color: #0066CC;
	          width: 256px;
	          text-align: center;
	      }
	      .style10
	      {
	          width: 237px;
	          text-align: center;
	          height: 26px;
	      }
	      .style11
	      {
	          width: 225px;
	          text-align: center;
	          height: 26px;
	      }
	      .style12
	      {
	          color: #0066CC;
	          width: 256px;
	          text-align: center;
	      }
	      .style13
	      {
	          color: #0066CC;
	          text-align: left;
	      }
	      .style14
	      {
	          width: 436px;
	          text-align: center;
	          height: 30px;
	      }
	      .style15
	      {
	          height: 30px;
	          color: #0066CC;
	          width: 256px;
	          text-align: center;
	      }
	      .style16
	      {
	          height: 30px;
	          color: #0066CC;
	          text-align: left;
	      }
	      .style17
	      {
	          width: 436px;
	          text-align: center;
	          height: 38px;
	      }
	  </style>
	</head>
	<body>
	  <form id="Form1" runat="server">        
	      <div class="clear">
	          <table style="width:100%;">
	              <tr>
	                  <td  colspan="2">
	                     <h3 class="style2"> <strong>New Member Sign Up Here</strong></h3></td>
	              </tr>
	              <tr>
	                  <td class="style15">
	                      User Name</td>
	                  <td class="style16">
	                      <asp:TextBox ID="Uname" runat="server" MaxLength="15"></asp:TextBox>
	                      <br />
	                      <asp:RequiredFieldValidator ID="re_user" runat="server"
	                           ControlToValidate="Uname" Display="Dynamic"
	                           ErrorMessage="Please enter the User Name" ForeColor="Red"
	                           ValidationGroup="signUp"></asp:RequiredFieldValidator>
	                  </td>
	              </tr>
	              <tr>
	                  <td class="style11">
	                      <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"
	                           ControlToValidate="UserName" ErrorMessage="Please Enter the User Name"
	                           ForeColor="Red" InitialValue="Username" ValidationGroup="login_gr"></asp:RequiredFieldValidator>
	                  </td>
	                  <td class="style10">
	                      <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server"
	                           ControlToValidate="PassLog" ErrorMessage="Please Enter the Password"
	                           ForeColor="Red" InitialValue="Password" ValidationGroup="login_gr"></asp:RequiredFieldValidator>
	                  </td>
	                  <td class="style12" rowspan="2">
	                      Gender</td>
	                  <td class="style13" rowspan="2">
	                      <asp:RadioButtonList ID="Gender" runat="server" RepeatDirection="Horizontal">
	                          <asp:ListItem>Male</asp:ListItem>
	                          <asp:ListItem>Female</asp:ListItem>
	                      </asp:RadioButtonList>
	                      <asp:RequiredFieldValidator ID="re_gender" runat="server"
	                           ControlToValidate="Gender" Display="Dynamic"
	                           ErrorMessage="Please Select the Gender" ForeColor="Red"
	                           ValidationGroup="signUp"></asp:RequiredFieldValidator>
	                  </td>
	              </tr>
	              <tr>
	                  <td class="style9">
	                      Password</td>
	                  <td class="style7">
	                      <asp:TextBox ID="Password" runat="server" MaxLength="8" TextMode="Password"></asp:TextBox>
	                      <br />
	                      <asp:RequiredFieldValidator ID="re_pass" runat="server"
	                           ControlToValidate="Password" Display="Dynamic"
	                           ErrorMessage="Please Enter the Password" ForeColor="Red"
	                           ValidationGroup="signUp"></asp:RequiredFieldValidator>
	                  </td>
	              </tr>
	              <tr>
	                  <td class="style1" colspan="2">
	                      &nbsp;</td>
	                  <td class="style9">
	                      Confirm Password</td>
	                  <td class="style7">
	                      <asp:TextBox ID="Cpassword" runat="server" MaxLength="8" TextMode="Password"></asp:TextBox>
	                      <br />
	                      <asp:RequiredFieldValidator ID="re_cpass" runat="server"
	                           ControlToValidate="Cpassword" Display="Dynamic"
	                           ErrorMessage="Please Enter the Confirm Password" ForeColor="Red"
	                           ValidationGroup="signUp"></asp:RequiredFieldValidator>
	                      <br />
	                      <asp:CompareValidator ID="re_passCompare" runat="server"
	                           ControlToCompare="Password" ControlToValidate="Cpassword" Display="Dynamic"
	                           ErrorMessage="Password Mismatch" ForeColor="Red" ValidationGroup="signUp"></asp:CompareValidator>
	                  </td>
	              </tr>
	              <tr>
	                  <td class="style1" colspan="2">
	                      &nbsp;</td>
	                  <td class="style9">
	                      Fees</td>
	                  <td class="style7">
	                      <asp:DropDownList ID="Fees" runat="server">
	                          <asp:ListItem></asp:ListItem>
	                          <asp:ListItem>299</asp:ListItem>
	                          <asp:ListItem>249</asp:ListItem>
	                          <asp:ListItem>Free User</asp:ListItem>
	                      </asp:DropDownList>
	                      <br />
	                      <asp:RequiredFieldValidator ID="re_fees" runat="server"
	                           ControlToValidate="Fees" ErrorMessage="Please Select the Fees" ForeColor="Red"
	                           ValidationGroup="signUp"></asp:RequiredFieldValidator>
	                  </td>
	              </tr>
	              <tr>
	                  <td class="style1" colspan="2">
	                      &nbsp;</td>
	                  <td class="style9">
	                      E-mail Id</td>
	                  <td class="style7">
	                      <asp:TextBox ID="eMail" runat="server"></asp:TextBox>
	                      <br />
	                      <asp:RequiredFieldValidator ID="re_email" runat="server"
	                           ControlToValidate="eMail" Display="Dynamic"
	                           ErrorMessage="Please Enter the Email" ForeColor="Red" ValidationGroup="signUp"></asp:RequiredFieldValidator>
	                      <br />
	                      <asp:RegularExpressionValidator ID="re_validemail" runat="server"
	                           ControlToValidate="eMail" Display="Dynamic"
	                           ErrorMessage="Enter the Valid Email Id" ForeColor="Red"
	                           ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"
	                           ValidationGroup="signUp"></asp:RegularExpressionValidator>
	                  </td>
	              </tr>
	              <tr>
	                  <td class="style1" colspan="2">
	                      &nbsp;</td>
	                  <td class="style8" colspan="2">
	                      <asp:Button ID="Button1" class="button_example" runat="server" Text="Sign Up"
	                           onclick="Button1_Click" ValidationGroup="signUp"
	                           />
	                  </td>
	              </tr>
	              <tr>
	                  <td class="style1" colspan="2">
	                      &nbsp;</td>
	                  <td class="style8" colspan="2">
	          <asp:Label runat="server" ID="message"></asp:Label>
	                  </td>
	              </tr>
	          </table>
	      </div>
	  </div>
	  </form>
	</body>
	</html>
Home.aspx.cs
	using System;
	using System.Collections.Generic;
	using System.Linq;
	using System.Web;
	using System.Web.UI;
	using System.Web.UI.WebControls;
	using BO;
	using BAL;
	
	namespace cdManage
	{
	   public partial class Home : System.Web.UI.Page
	   {
	       boRegister register = new boRegister();//object for bo class
	       balRegister balregister = new balRegister();//object for bal class
	       protected void Page_Load(object sender, EventArgs e)
	       {
	       }
	       protected void Button1_Click(object sender, EventArgs e)
	       {
	           register.userName = Uname.Text;
	           register.gender = Gender.SelectedValue;
	           register.password = Password.Text;
	           register.cPassword = Cpassword.Text;
	           register.fees = Fees.SelectedValue;
	           register.eMail = eMail.Text;
	           if (Fees.SelectedIndex ==1)//According to selecting value in dropdown list taking user type as level1,level2,..
	               register.userType = "Level1";
	           if (Fees.SelectedIndex == 2)
	               register.userType = "Level2";
	           else if(Fees.SelectedIndex == 3)
	               register.userType = "Level3";
	           int value= balregister.balreg(register);
	           Uname.Text = "";
	           Gender.ClearSelection();
	           Fees.SelectedIndex = 0;
	           eMail.Text = "";
	           if (value == 1)
	           {
	               message.Text = "Registered Successfully";
	           }
	           else
	           {
	               message.Text = "User Name Not Available.Try With Different User Name";
	           }
	       }
	   }
	}
BoRegister.cs(Business objects)
	using System;
	using System.Collections.Generic;
	using System.Linq;
	using System.Text;
	
	namespace BO
	{
	   public class boRegister
	   {
	       private string _userName;
	       public string userName
	       {
	           get { return _userName; }
	           set { _userName = value; }
	       }
	       private string _gender;
	       public string gender
	       {
	           get { return _gender; }
	           set { _gender = value; }
	       }
	       private string _fees;
	       public string fees
	       {
	           get { return _fees; }
	           set { _fees = value; }
	       }
	       private string _password;
	       public string password
	       {
	           get { return _password; }
	           set { _password = value; }
	       }
	       private string _cPassword;
	       public string cPassword
	       {
	           get { return _cPassword; }
	           set { _cPassword = value; }
	       }
	       private string _eMail;
	       public string eMail
	       {
	           get { return _eMail; }
	           set { _eMail = value; }
	       }
	       private string _usertype;
	       public string userType
	       {
	           get { return _usertype; }
	           set { _usertype = value; }
	       }
	   }
	}
Best Lessons of "Asp.net/Ado.net/C#.net(Dotnet)"
Top lessons which are viewed more times.
  Copyright © 2014 Knowledge walls, All rights reserved
KnowledgeWalls
keep your tutorials and learnings with KnowledgeWalls. Don't lose your learnings hereafter. Save and revise it whenever required.
Click here for more details