Registration/SignUp form for Social Networking Website like facebook using asp.net


Registration/SignUp form for Social Networking Website like facebook using asp.net csharp(c#)


  1. Registration and signup form is useful to register new users who can join the social network.
  2. While Registering the user we are taking various parameters along the profile picture

Default.aspx Code:

  1. Open Default.aspx and In the Source of Default.aspx you can add the following piece of code given below.
  2. We have added this defualt page as register form page under HomeMaster master page.
  3. We have designed a Signup form inside a tabular structure.
  4. On the left side of registration form we have placed the logo with an animated heartbeat logo

<%@ Page Title="Social Networking Site using asp.net,c#,sqlserver" 
Language="C#" MasterPageFile="~/HomeMaster.master"
AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
    <table class="style2" 
        style="border-bottom: thin solid #000000; width: 910px; 
        border-left-color: #000000; border-left-width: medium; 
        border-right-color: #000000; border-right-width: medium; 
        border-top-color: #000000; border-top-width: medium;">
        <tr>
            <td align="center" class="style3" rowspan="2">
                <asp:Image ID="Image1" runat="server" Height="280px" 
                    ImageUrl="~/images/heartsanimated.gif" Width="349px" />
                <br />
                <br />
                <asp:Label ID="Label2" runat="server" Font-Names="Raavi" Font-Bold="True">
                If your Heart Beats for Your Friends .Join HeartBeat</asp:Label>
            </td>
            <td align="center" 
            style="border-left-style: solid; border-width: medium; border-color: #3366CC">
                
           
            <table style="width: 80%">
                    <tr>
                        <td colspan="2">
                           
                         
                         </td>
                    </tr>
                    <tr>
                        <td style="width: 207px">
                             </td>
                        <td>
                             </td>
                    </tr>
                    <tr>
                        <td style="width: 207px">
                            YourName</td>
                        <td align="left">
                            <asp:TextBox ID="txtName" runat="server"></asp:TextBox>
                        </td>
                    </tr>
                    <tr>
                        <td style="width: 207px">
                            Email</td>
                        <td align="left">
                            <asp:TextBox ID="txtEmail" runat="server"></asp:TextBox>
                        </td>
                    </tr>
                    <tr>
                        <td style="height: 23px; width: 207px">
                            Password</td>
                        <td style="height: 23px" align="left">
                            <asp:TextBox ID="txtPassword" runat="server" TextMode="Password">
                            </asp:TextBox>
                        </td>
                    </tr>
                    <tr>
                        <td style="width: 207px">
                            Gender</td>
                        <td align="left">
                            
                            <asp:DropDownList ID="ddlGender" runat="server"  Width="150px" >
                                <asp:ListItem>SelectGender</asp:ListItem>
                                <asp:ListItem>Male</asp:ListItem>
                                <asp:ListItem>Female</asp:ListItem>
                             
                            </asp:DropDownList>
                            
                        </td>
                    </tr>
                    <tr>
                        <td style="width: 207px; height: 26px;">
                            DateofBirth</td>
                        <td style="height: 26px" align="left">
                            <asp:DropDownList ID="ddlDay" runat="server">
                                <asp:ListItem>Day</asp:ListItem>
                                <asp:ListItem>1</asp:ListItem>
                            
                            </asp:DropDownList>
                            <asp:DropDownList ID="ddlMonth" runat="server">
                                <asp:ListItem>Month</asp:ListItem>
                                <asp:ListItem>Jan</asp:ListItem>
                            </asp:DropDownList>
                            <asp:DropDownList ID="ddlYear" runat="server">
                                <asp:ListItem>Year</asp:ListItem>
                                <asp:ListItem>2012</asp:ListItem>
                            </asp:DropDownList>
                        </td>
                    </tr>
                    <tr>
                        <td style="width: 207px">
                            Your Photo</td>
                        <td align="left">
                            <asp:FileUpload ID="uploadPhoto" runat="server" />
                        </td>
                    </tr>
                    <tr>
                        <td style="width: 207px">
                            About Me </td>
                        <td align="left">
                            <asp:TextBox ID="txtAboutMe" runat="server" Height="63px" TextMode="MultiLine" 
                                Width="216px"></asp:TextBox>
                        </td>
                    </tr>
                    <tr>
                        <td style="width: 207px">
                            Country</td>
                        <td align="left">
                            <asp:TextBox ID="txtCountry" runat="server"></asp:TextBox>
                        </td>
                    </tr>
                    <tr>
                        <td style="width: 207px">
                             </td>
                        <td>
                             </td>
                    </tr>
                    <tr>
                        <td style="width: 207px">
                             </td>
                        <td align="left">
                            <asp:Button ID="btnRegister" runat="server" Text="Register" 
                                onclick="btnRegister_Click" />
                        </td>
                    </tr>
                    <tr>
                        <td style="width: 207px">
                             </td>
                        <td>
                             </td>
                    </tr>
                    <tr>
                        <td style="width: 207px">
                             </td>
                        <td>
                             </td>
                    </tr>
                    <tr>
                        <td style="width: 207px">
                             </td>
                        <td>
                             </td>
                    </tr>
                    </table>  
        
            
            </td>
        </tr>
     
    </table>
</asp:Content>
  
  1. Now Open the Code behind file of Default page. 
  2. In Default.aspx.cs file you can add the following piece of code given below.
  3. on Default.aspx page we have Register OnClick event which is inserting all the records in Register table.Before inserting the profile picture into database we are converting it into bytes.
  4. To store image we have taken a byte array and storing in file memory.
  5. Once the Registration is done successfully we are showing the Alert using Alert.Show() Method.
  6. Finally we are clearing all the contents of the controls and making them empty

Default.aspx.cs C# Code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;
using System.Web.Configuration;

public partial class _Default : System.Web.UI.Page
{

    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void btnRegister_Click(object sender, EventArgs e)
    {
        
        string DOB = ddlDay.SelectedValue + " " + ddlMonth.SelectedValue + " " + ddlYear.SelectedValue;
        byte[] profilePicBytes = null;
        if (uploadPhoto.HasFile)
        {
            //getting length of uploaded file
            int length = uploadPhoto.PostedFile.ContentLength;
            //create a byte array to store the binary image data
            profilePicBytes = new byte[length];
            //store the currently selected file in memeory
            HttpPostedFile img = uploadPhoto.PostedFile;
            //set the binary data
            img.InputStream.Read(profilePicBytes, 0, length);
        }


        try
        {

            SqlConnection connection = new SqlConnection(Database.connString);
            connection.Open();
            SqlCommand cmd = new SqlCommand("Insert into Register (ProfilePic,Name,EmailId,Pwd,Gender,DOB,AboutMe,Country) VALUES (@ProfilePic,@Name,@Email,@Pwd,@Gender,@DOB,@AboutMe,@Country)", connection);
            cmd.Parameters.Add("@ProfilePic", SqlDbType.Image).Value = profilePicBytes;
            cmd.Parameters.Add("@Name", SqlDbType.VarChar, 50).Value = txtName.Text;
            cmd.Parameters.Add("@Email", SqlDbType.VarChar, 50).Value = txtEmail.Text;
            cmd.Parameters.Add("@Pwd", SqlDbType.VarChar, 50).Value = txtPassword.Text;
            cmd.Parameters.Add("@Gender", SqlDbType.VarChar, 10).Value = ddlGender.SelectedItem.Text;
            cmd.Parameters.Add("@DOB", SqlDbType.VarChar, 10).Value = DOB;
            cmd.Parameters.Add("@AboutMe", SqlDbType.VarChar, 500).Value = txtAboutMe.Text;
            
            cmd.Parameters.Add("@Country", SqlDbType.VarChar, 30).Value = txtCountry.Text;


            cmd.ExecuteNonQuery();
            connection.Close();

            Alert.Show("Registration Done Successfully");
            clearControls();

        }
        catch (Exception ex)
        {

            throw ex;
        }
        
    }

    private void clearControls()
    {
        txtName.Text = string.Empty;
        txtEmail.Text = string.Empty;
        txtAboutMe.Text = string.Empty;
        txtCountry.Text = string.Empty;
        ddlGender.SelectedIndex = 0;
        ddlDay.SelectedIndex = 0;
        ddlMonth.SelectedIndex = 0;
        ddlYear.SelectedIndex = 0;
    }

    
}

0 comments:

Post a Comment