Home

Friday, 15 July 2016

User Registration application using c# Asp.net

Step 1) Add a Page Aspx page in application and Write below code on aspx page.
<body>
    <form id="form1" runat="server">
    <div>
        .<table class="auto-style1">
            <tr>
                <td class="auto-style2" colspan="2"><strong>&nbsp;New User Register Here</strong></td>
            </tr>
            <tr>
                <td class="auto-style4">&nbsp;</td>
                <td>&nbsp;</td>
            </tr>
            <tr>
                <td class="auto-style5">Name</td>
                <td>
                    <asp:TextBox ID="txtname" runat="server" Width="269px"></asp:TextBox>
                </td>
            </tr>
            <tr>
                <td class="auto-style5">Password</td>
                <td>
                    <asp:TextBox ID="txtpassword" runat="server" TextMode="Password" Width="269px"></asp:TextBox>
                </td>
            </tr>
            <tr>
                <td class="auto-style5"><strong>Confirm Password</strong></td>
                <td>
                    <asp:TextBox ID="txtconfirmpass" runat="server" TextMode="Password" Width="269px"></asp:TextBox>
                </td>
            </tr>
            <tr>
                <td class="auto-style5">Address</td>
                <td>
                    <asp:TextBox ID="txtAddress" runat="server" TextMode="MultiLine" Width="269px"></asp:TextBox>
                </td>
            </tr>
            <tr>
                <td class="auto-style5">EmailId</td>
                <td>
                    <asp:TextBox ID="txtEmailId" runat="server" Width="269px"></asp:TextBox>
                </td>
            </tr>
            <tr>
                <td class="auto-style5">Mobileno</td>
                <td>
                    <asp:TextBox ID="txtMobile" runat="server" Width="269px"></asp:TextBox>
                </td>
            </tr>
            <tr>
                <td class="auto-style3">&nbsp;</td>
                <td>&nbsp;</td>
            </tr>
            <tr>
                <td class="auto-style4">&nbsp;</td>
                <td>
                    <asp:Button ID="btnRegister" runat="server" OnClick="btnRegister_Click" Text="Register" Width="85px" />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                    <asp:Button ID="btnlogin" runat="server" OnClick="btnlogin_Click" Text="Login" Width="72px" />
                </td>
            </tr>
        </table>
    </div>
    </form>
</body>

Step 2) After that on btnRegistration Event add below code
  protected void btnRegister_Click(object sender, EventArgs e)
        {
            BusinessLogic bl = new BusinessLogic();
            BusinessObject bo = new BusinessObject();
            bo.Name = txtname.Text;
            bo.Password = txtpassword.Text;
            bo.Address = txtAddress.Text;
            bo.Email = txtEmailId.Text;
            bo.MobileNo = txtMobile.Text;
            int result = bl.insertUserDetails(bo);
            if (result > 0)
            {
                ScriptManager.RegisterStartupScript(this, this.GetType(), "alert", "alert('User Register Successfully'),window.location.href = 'Login.aspx'", true);
                //Response.Redirect("Login.aspx");
            }

        }

Step 3) Add below code in Bussiness logic class library class
public int insertUserDetails(BusinessObject bo)
        {
            try
            {
                return dal.AddUserDetails(bo);
            }
            catch
            {
                throw;
            }
        }
Step 4) After that use below code for data base intraction and add data in Sql Server.
 SqlConnection con = new SqlConnection("Data Source=.;Initial Catalog=TestProj;Integrated Security=True");
        public int AddUserDetails(BusinessObject userdetails)
        {
            try
            {
                SqlCommand cmd = new SqlCommand("userdetails", con);
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.AddWithValue("@Name", userdetails.Name);
                cmd.Parameters.AddWithValue("@Password", userdetails.Password);
                cmd.Parameters.AddWithValue("@Address", userdetails.Address);
                cmd.Parameters.AddWithValue("@Email", userdetails.Email);
                cmd.Parameters.AddWithValue("@MobileNo", userdetails.MobileNo);
                con.Open();
                int res = cmd.ExecuteNonQuery();
                return res;
            }
            catch 
            {
                throw;
            }
            finally
            {
                con.Dispose();
                con.Close();
            }
        }
Step 4) Where BussinessObject is class contain below code
 public class BusinessObject
    {
        private int id;
        public int Id
        {
            get { return id; }
            set { id = value; }
        }
        private string name;

        public string Name
        {
            get { return name; }
            set { name = value; }
        }
        private string address;
        public string Address
        {
            get { return address; }
            set { address = value; }
        }
        private string email;

        public string Email
        {
            get { return email; }
            set { email = value; }
        }
        private string mobileNo;
        public string MobileNo
        {
            get { return mobileNo; }
            set { mobileNo = value; }
        }
        private string password;
        public string Password
        {
            get { return password; }
            set { password = value; }
        }
    }
Step 5) After using this successfully intract with database and user inserted in Sql Server Data base.

No comments:

Post a Comment