Showing posts with label Projects. Show all posts
Showing posts with label Projects. Show all posts

online shopping cart project aspnet c# source code

Online Shopping Cart free project Asp.Net with source code 

  1. This project can be used for online mobile store or online book store project  as well.
  2. This article is about shopping cart project open source website in asp.net with c# and sql server as backend.
  3. we will go through each module of this project.we have named this project as shopping heart.for those who love shopping.
20fingers2brains projects live demo
The main features that are included in this shopping cart project in asp.net c# are as follows
  1. Shopping cart project is divided into two main modules Admin Module and user module.
  2. Add to cart functionality and remove from cart functionlity for every user
  3. Admin will enter the product details into a product category.
  4. Admin will enter product category, product description,product price and save the shopping product details
  5. Once the details are saved by admin the product will be available in the user module
  6. User can see the product and can also perform add to cart 
  7. User can view the cart and see the number of products in the cart 
  8. Also user can see the product total amount in the MyCart
Online user chat can be integrated with this shopping cart to resolve the queires of the shopping users.
Shopping Cart User Module is shown below

  1. This shopping cart as shown above is having all the list of products on right side 
  2. when any user clicks on the product category it will see the products in that particular category.
  3. If user selects mobile phones shopping cart will display all the mobile phones same in the case of laptops and other products.
  4. On clicking on Add to Cart the product count  in the header will increase.and user can check the products by clicking on the product count.
20fingers2brains projects live demo

20fingers2brains projects live demo

Entire Project Source Code is Shown in Below 22 Videos



Part 21 Shopping Cart Source Code :

Facebook Like Header User Control using Asp.net for Social networking website



Facebook Like Header User Control using Asp.net for Social networking website



  1. We have created a Header similar to facebook header with Heartbeat logo,Notifications icon,Messages icon and Friend Requests icon,Search Box and Logout button.
  2. To create a facebook like header we have created a user control and used it on profile master page


Header.ascx Code:



  1. Open Header.ascx User Control Which You have created in Controls Folder. 
  2. In the Source of Header.ascx user control you can add the following piece of code given below. 
  3. We have created a user control and named it as Header. 
  4. On the user control we have make a tabular structure and properly alligned the logo and other images,seach box and logout button. We have also added AutoCompleteExtender and TextBoxWatermarkExtender on the header control


<%@ Control Language="C#" AutoEventWireup="true" CodeFile="Header.ascx.cs" Inherits="Controls_Header" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>
<style type="text/css">
    .HeaderStyle
    {
        width: 80px;
        padding-right: 7px;
    }
    .LogoStyle
    {
        width: 50px;
        padding-right: 7px;
    }
    .Red
    {
        color: Red;
        font-weight: bold;
    }
</style>
<table cellpadding="0" cellspacing="1" width="900px">
    <tr>
        <td align="center" class="LogoStyle">
            <asp:LinkButton ID="btnLogo" runat="server" Font-Bold="True" 
            Font-Names="Franklin Gothic Medium"
            Font-Underline="False" ForeColor="White" 
            Font-Size="Large" 
            OnClick="btnLogo_Click">HeartBeat</asp:LinkButton>
        </td>
        <td class="HeaderStyle">
            <table>
                <tr>
                    <td>
                        <asp:HyperLink ID="HyperLink1" runat="server" 
                        ImageUrl="~/images/globe.png"></asp:HyperLink>
                    </td>
                    <td>
                        <asp:ImageButton ID="imgBtnMsg" runat="server" 
                        ImageUrl="~/images/msgr.png" />
                    </td>
                    <td>
                        <asp:ImageButton ID="imgBtnFrendReq" runat="server" 
                        ImageUrl="~/images/friendRequest.png" />
                    </td>
                </tr>
            </table>
        </td>
        <td align="left">
            <asp:TextBox ID="txtSearch" runat="server" Width="300px" 
            Height="21px"></asp:TextBox>

            <asp:TextBoxWatermarkExtender ID="txtSearch_TextBoxWatermarkExtender" 
            runat="server" Enabled="True" 
            TargetControlID="txtSearch" WatermarkText="Search Friends..">
            </asp:TextBoxWatermarkExtender>

            <asp:AutoCompleteExtender ID="txtSearch_AutoCompleteExtender" 
            runat="server" DelimiterCharacters="" ServiceMethod="SearchFriends" 
            Enabled="True" TargetControlID="txtSearch" ServicePath="~/WebService.asmx"
            CompletionInterval="100" MinimumPrefixLength="1">
            </asp:AutoCompleteExtender>

            <asp:Button ID="btnSearch" runat="server" Text="Search"
             OnClick="btnSearch_Click" BorderColor="#0033CC" 
             BorderStyle="Ridge" Font-Bold="True" ForeColor="Black"
             Height="27px" />

        </td>
        <td align="right">
            <asp:LinkButton ID="btnLogout" runat="server" 
            Font-Bold="False" ForeColor="White"
            OnClick="btnLogout_Click" 
            Font-Names="Arial Rounded MT Bold" 
            Font-Underline="False">Logout</asp:LinkButton>
        </td>
    </tr>
</table>


Header.ascx.cs C# Code:



  1. Now Open the Code behind file of Header User Control. 
  2. In Header.ascx.cs file you can add the following piece of code given below. 
  3. In the csharp file of header control we have three OnClick as Logo Click , Logout Button Click and Search Button Click.
  4. On Logo Click we are changing the session.On Logout Button Click we are redirecting the user to login page and Search Button we are directing the user to Search page


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

public partial class Controls_Header : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        
    }
    
    protected void btnLogo_Click(object sender, EventArgs e)
    {
        Session["UserId"] = Session["UserId"];
        Session["CurrentProfileId"] = Session["UserId"];
        Response.Redirect("Main.aspx");
        
    }
    protected void btnLogout_Click(object sender, EventArgs e)
    {
        Response.Redirect("Default.aspx");
    }
    protected void btnSearch_Click(object sender, EventArgs e)
    {
        Session["SearchText"]=txtSearch.Text;
        Response.Redirect("~/Search.aspx");
    }
}

Friend List User Control in a Social Networking website using asp.net csharp


User Friend List User Control in a Social Networking website using asp.net csharp


  1. Friend List is very important part of any social networking project then it may be facebook or twitter or google plus the names may be different facebook calls it friend list,twitter calls it followers and google plus calls it cirlces, but the functionlity is similar. 
  2. We have also created Friendlist on HeartBeat to show the Friends of User.
  3. For this we have created a different user control and named it as Friends

Friends.ascx Code:


  1. Open Friends.ascx User Control Which You have created in Controls Folder.
  2.  In the Source of Friends.ascx user control you can add the following piece of code given below.
  3. On the User control we have dragged dropped one datalist and inside the item template we have created a tabular structure to show the Friends Photo and Name.
  4. As we have stored user images inside our database and not in any folder.
  5. We have converted our profile pictures into bytes and stored in database field of datatype image.
  6. So to retrive it and showing it in a datalist we have made use of ImageHandler and by passing the RegisterId we are fetching the profile picture and binding it to datalist

 <%@ Control Language="C#" AutoEventWireup="true" CodeFile="Friends.ascx.cs" Inherits="Controls_Friends" %>
<style type="text/css">
    .styleFriends
    {
        width: 100%;
    }
    .friendsTD
    {
        width: 20%;
        text-align: center;
    }
</style>
<asp:DataList ID="dlFriends" runat="server" Width="100%">
    <ItemTemplate>
        <table cellpadding="2" class="styleFriends" style="border: 1px ridge #CCCCCC">
            <tr>
                <td class="friendsTD" rowspan="2">
                    <asp:ImageButton ID="imgbtnYou" runat="server" Height="84px" Width="84px" 
                    ImageUrl='<%# "ImageHandler.ashx?RegisterId="+ Eval("RegisterId") %>'
                    BorderColor="#CCCCCC" BorderStyle="Ridge" BorderWidth="1px" OnClick="imgbtnYou_Click"
                    CommandArgument='<%#Bind("RegisterId") %>' />
                </td>
                <td align="left">
                    <asp:Label ID="lblFriendName" runat="server" Font-Bold="False" Font-Names="Franklin Gothic Medium"
                        Text='<%# Bind("Name") %>'></asp:Label>
                </td>
            </tr>
            <tr>
                <td>
                     
                </td>
            </tr>
        </table>
    </ItemTemplate>
</asp:DataList>

    
 

Friends.ascx.cs C# Code:


  1. Now Open the Code behind file of Friends User Control. In Friends.ascx.cs file you can add the following piece of code given below.
  2. If you see the below code from the Page load method we are calling a function MyFriends() which is responsible finding the friends of the current profile which is being viewed.
  3. If it is your profile it will show your friends and if it is other profile it will his her friends.
  4. We have written a query to get those friends whose Friendhsip status is Accepted and not Pending or Rejected.
  5. To achieve this we have made a join and union between Register table and Friends Table.Finally we are checking whether the query has returned any records or not.
  6. If records are there then we are binding it to datalist.Once the User Control is ready we are dragging and dropping it from the Solution Explorer onto the page where we want it to be.
  7. In this way the usercontrol we will be registred on to that page.we can also call the control by manually wrting the aspx tags

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

public partial class Controls_Friends : System.Web.UI.UserControl
{
    DataTable dt = new DataTable();
    protected void Page_Load(object sender, EventArgs e)
    {
            MyFriends();
    }

    private void MyFriends()
    {

        string getFriendQuery = "Select * FROM [Register] where RegisterId IN (SELECT MyId  FROM Friends WHERE FriendId='" + Session["CurrentProfileId"] + "' AND Status=1 UNION SELECT FriendId  FROM Friends WHERE MyId='" + Session["CurrentProfileId"] + "' AND Status=1) ";
        dt = Database.GetData(getFriendQuery);
        if (dt.Rows.Count > 0)
        {
            dlFriends.DataSource = dt;
            dlFriends.DataBind();
        }

    }
    protected void imgbtnYou_Click(object sender, ImageClickEventArgs e)
    {
        Session["CurrentProfileId"]=(((ImageButton)sender).CommandArgument).ToString();
        Response.Redirect("Main.aspx");
    }
}

Friends.aspx Code:


  1. Once the Friends.ascx user control is ready we have to add it to Friends.aspx page as shown below code snippet.
  2. Here we have done nothing but dragged dropped the user control on the Friends.aspx page

   <%@ Page Title="" Language="C#" MasterPageFile="~/ProfileMaster.master" 
   AutoEventWireup="true" CodeFile="Friends.aspx.cs" Inherits="Friends" 
   EnableEventValidation="false" %>

<%@ Register src="Controls/Friends.ascx" tagname="Friends" tagprefix="uc1" %>
<%@ Register src="Controls/FriendRequests.ascx" tagname="FriendRequests" tagprefix="uc2" %>

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
    <table cellpadding="3" cellspacing="3" style="width: 100%">
        <tr>
            <td>
                <uc2:FriendRequests ID="FriendRequests1" runat="server" />
            </td>
        </tr>
        <tr>
            <td align="center">
                <asp:Label ID="Label1" runat="server" Text="Your Friends Your HeartBeats" 
                    Font-Names="Franklin Gothic Medium"></asp:Label>
                <br />
                <hr />
            </td>
        </tr>
        <tr>
            <td>
                <uc1:Friends ID="Friends1" runat="server" />
            </td>
        </tr>
        <tr>
            <td>
                 </td>
        </tr>
    </table>
</asp:Content>


Sending Friend Request Like Facebook in Social networking using asp.net



Sending Friend Request Like Facebook in Social networking using asp.net csharp(c#)

  1. Friend Requests are a very important part of any social networking website.
  2. To Receive the Friend requests we have created a user control.In this user control we have shown the username ,photo along with accept and reject button.
  3. We are showing the Friends Requests above the Friendlist so that the changes are refelected direclty in the friendlist when the user accept or reject any friend request

FriendRequests.ascx Code:

  1. Open FriendRequests.ascx User Control Which You have created in Controls Folder.
  2. In the Source of FriendRequests.ascx user control you can add the following piece of code given below.
  3. In FriendRequests user control we have created a tabular structure and in that tabular structure we have dragged dropped one datalist and two link buttons for accept and reject.
  4. Datalists Itemtemplate contains the user profile picture and also the username.
  5. As always we are binding the image to profile picture using image handler.
  6. We have also binded the RegisterId to Accept and Reject Button in the form of command argument so that we can update the frienship status properly when the user clicks accept or reject button. 
  7. Finally we are adding this control to Friends.aspx page


<%@ Control Language="C#" AutoEventWireup="true" CodeFile="FriendRequests.ascx.cs"
    Inherits="Controls_FriendRequests" %>
<asp:DataList ID="dlFriendRequests" runat="server" Width="100%">
    <ItemTemplate>
        <table cellpadding="2" style="border: 1px ridge #CCCCCC; width: 100%;">
            <tr>
                <td class="style1" rowspan="2" align="center">
                    <asp:ImageButton ID="imgbtnYou" runat="server" BorderColor="#CCCCCC" BorderStyle="Ridge"
                        BorderWidth="1px" CommandArgument='<%#Bind("RegisterId") %>' 
                        Height="84px" ImageUrl='<%# "ImageHandler.ashx?RegisterId="+ Eval("RegisterId") %>'
                        OnClick="imgbtnYou_Click" Width="84px" />
                </td>
                <td align="left">
                    <asp:Label ID="lblFriendName" runat="server" Font-Bold="False" 
                    Font-Names="Franklin Gothic Medium"
                    Text='<%# Bind("Name") %>'></asp:Label>
                </td>
            </tr>
            <tr>
                <td>
                    <asp:Button ID="Accept" runat="server" ToolTip="Accept" 
                    Text="Accept" OnClick="Accept_Click"
                     CommandArgument='<%# Bind("RegisterId") %>' /> 
                    <asp:Button ID="Reject" runat="server" ToolTip="Reject" Text="Reject" Width="59px"
                    CommandArgument='<%#Bind("RegisterId") %>' OnClick="Reject_Click" />
                </td>
            </tr>
        </table>
    </ItemTemplate>
</asp:DataList>

    

FriendRequests.ascx.cs C# Code:

  1. Now Open the Code behind file of Friends User Control. In FriendRequests.ascx.cs file you can add the following piece of code given below.
  2. In code behind from page load method we are calling a function ShowFriendRequests().
  3. This function will check for friends requests from database and if there is a friend rquests it will bind it to the friendlist datalist.
  4. We have added a userid equals currentprofileid so that we only see ours friend requests and not others friend requests.
  5. To get the friend requests we have made a sub query between register table and friends table and checking the friendship status as zero.while checking the friend requests if the user clicks on the profile picture of the friendrequests then we are diverting it to his her profile.
  6. We also have two Button Click Events Accept and Reject.On Accept we are updating the friendship status with one and On Reject we are updating the friendship status with two.
  7. To get the friendId we have made use of Command Argument so that we can update the friendship status for particular user only.


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Web.UI.HtmlControls;

public partial class Controls_FriendRequests : System.Web.UI.UserControl
{

    protected void Page_Load(object sender, EventArgs e)
    {
        ShowFriendRequests();
    }
    private void ShowFriendRequests()
    {
        if (Session["UserId"] == Session["CurrentProfileId"])
        {
            DataTable dt = new DataTable();
            string query = "Select * FROM [Register]  where RegisterId IN (SELECT MyId  FROM Friends WHERE FriendId='" + Session["UserId"] + "' AND Status=0) ";
            dt = Database.GetData(query);

            if (dt.Rows.Count > 0)
            {

                dlFriendRequests.DataSource = dt;
                dlFriendRequests.DataBind();
            }
            else
            {

            }
        }

    }

    protected void imgbtnYou_Click(object sender, ImageClickEventArgs e)
    {
        Session["CurrentProfileId"] = (((ImageButton)sender).CommandArgument).ToString();
        Response.Redirect("Main.aspx");
    }

    protected void Accept_Click(object sender, EventArgs e)
    {
        string SenderFriendId = (((Button)sender).CommandArgument).ToString();
        string MyID = Session["UserId"].ToString();
        string AcceptFriendQuery = "Update Friends set Status=1 
        where MyId='" + SenderFriendId + "' AND FriendId='" + MyID + "'";
        Database.UpdateData(AcceptFriendQuery);
        Response.Redirect("~/Friends.aspx");
    }
    protected void Reject_Click(object sender, EventArgs e)
    {
        string SenderFriendId = (((Button)sender).CommandArgument).ToString();
        string MyID = Session["UserId"].ToString();
        string RejectFriendQuery = "Update Friends set Status=2 
        where MyId='" + SenderFriendId + "' AND FriendId='" + MyID + "'";
        Database.UpdateData(RejectFriendQuery);
        Response.Redirect("~/Friends.aspx");
    }
}

    

Friends.aspx Code:

  1. Once the FriendRequests.ascx user control is ready we have to add it to Search.aspx page as shown below code snippet.
  2. Here we have done nothing but dragged dropped the user control on the Friends.aspx page


   <%@ Page Title="" Language="C#" MasterPageFile="~/ProfileMaster.master" 
   AutoEventWireup="true" CodeFile="Friends.aspx.cs" Inherits="Friends" 
   EnableEventValidation="false" %>

<%@ Register src="Controls/Friends.ascx" tagname="Friends" tagprefix="uc1" %>
<%@ Register src="Controls/FriendRequests.ascx" tagname="FriendRequests" tagprefix="uc2" %>

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
    <table cellpadding="3" cellspacing="3" style="width: 100%">
        <tr>
            <td>
                <uc2:FriendRequests ID="FriendRequests1" runat="server" />
            </td>
        </tr>
        <tr>
            <td align="center">
                <asp:Label ID="Label1" runat="server" Text="Your Friends Your HeartBeats" 
                    Font-Names="Franklin Gothic Medium"></asp:Label>
                <br />
                <hr />
            </td>
        </tr>
        <tr>
            <td>
                <uc1:Friends ID="Friends1" runat="server" />
            </td>
        </tr>
        <tr>
            <td>
                 </td>
        </tr>
    </table>
</asp:Content>

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;
    }

    
}

Login Register form in asp.net for social networking website


Home MasterPage and Login or SignIn Form for Social Networking Website using asp.net csharp


  1. The Login or SignIn form on our social network heartbeat is a part of master page.
  2. The Login form is having the basic fields emailid,password,remember me and forget password

HomeMaster.master Code:

  1. Open HomeMaster.master MasterPage Which You have created In the Source of HomeMaster.master you can add the following piece of code given below.
  2. We have added the login form on the master page itself.
  3. On HomeMaster.master page we have made a struture some what similar to facebook.
  4. The login form contains EmailId Password fields which are compulsory for the user to authinticate.
  5. We have a content place holder to hold the register page below the login form.On the footer we have written the copyright notice to 99coding examples

<%@ Master Language="C#" AutoEventWireup="true" CodeFile="HomeMaster.master.cs" Inherits="HomeMaster" %>

<!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>
    <style type="text/css">
        .style1
        {
            width: 900px;
        }
        .style2
        {
            width: 100%;
        }
        
        .style3
        {
            width: 382px;
        }
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server">
    </asp:ScriptManager>
    <table align="center" class="style1" style="border: 1px ridge #0066CC">
        <tr>
            <td>
                <table class="style2" style="border-bottom: medium 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; background-color: #3366CC;">
                    <tr>
                        <td align="center" class="style3" rowspan="3">
                            <asp:Label ID="Label1" runat="server" Font-Names="Impact" Font-Size="30pt" Text="HeartBeat"
                                ForeColor="White"></asp:Label>
                        </td>
                        <td align="left">
                            <asp:Label ID="Label2" runat="server" Text="Email" ForeColor="White"></asp:Label>
                        </td>
                        <td align="left">
                            <asp:Label ID="Label3" runat="server" Text="Password" ForeColor="White"></asp:Label>
                        </td>
            </td>
            <td align="left">
            </td>
        </tr>
        <tr>
            <td align="left">
                <asp:TextBox ID="txtLoginEmail" runat="server"></asp:TextBox>
            </td>
            <td align="left">
                <asp:TextBox ID="txtLoginPassword" runat="server" TextMode="Password"></asp:TextBox>
            </td>
            <td align="left">
                <asp:Button ID="btnLogin" runat="server" Text="Login" OnClick="btnLogin_Click" />
            </td>
        </tr>
        <tr>
            <td align="left">
                <asp:CheckBox ID="CheckBox1" runat="server" Text="RememberMe" ForeColor="White" />
            </td>
            <td align="left">
                <asp:LinkButton ID="LinkButton1" runat="server" ForeColor="White">ForgotPassword.?</asp:LinkButton>
            </td>
            <td align="left">
            </td>
        </tr>
    </table>
    </td> </tr>
    <tr>
        <td>
            <asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">
            </asp:ContentPlaceHolder>
        </td>
    </tr>
    <tr>
        <td style="color: #FFFFFF; background-color: #3366CC;">
             © Copyright -99CodingExamples.com
        </td>
    </tr>
    </table>
    </form>
</body>
</html>

    

HomeMaster.master.cs C# Code:

  1. Now Open the Code behind file of HomeMaster.master master page 
  2. In HomeMaster.master.cs file you can add the following piece of code given below.
  3. In the codebehind we have an LoginButton Onclick event which checks whether the emailid and password entered by user are correct or not.
  4. If user have entered wrong email password we are showing the alert box with the message

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

public partial class HomeMaster : System.Web.UI.MasterPage
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void btnLogin_Click(object sender, EventArgs e)
    {
        DataTable dt = new DataTable();
        string query = "Select * from Register where EmailId='" + txtLoginEmail.Text + "' and Pwd='" + txtLoginPassword.Text + "'";
        dt = Database.GetData(query);
        if (dt.Rows.Count > 0 && dt != null)
        {
            Session["UserId"]=dt.Rows[0]["RegisterId"];
            Session["CurrentProfileId"] = Session["UserId"];
            Session["Name"]=dt.Rows[0]["Name"];
            string MyID = Session["UserId"].ToString();
            string AcceptFriendQuery = "Update Friends set MeOnline=1 where MyId='" + Session["UserId"] + "'";
            Database.UpdateData(AcceptFriendQuery);
            Response.Redirect("~/Main.aspx");
        }
        else
        {
            Alert.Show("Incorrect UserName/Password ");
        }

    }
}



SocialNetworking Website Database Structure in SQL Server

Database Structure and Tables for SocialNetworking Website in SQL Server

Open SQL Server Management Studio 2008/2005 and Open a new Query Window.You can also open new query window using shortcut key Clt+N
In the New Query Window create a database Named HeartBeatDB using the Following Script
use master
create database HeartBeatDB
go
    

Database Tables SQL Script:

For this project we are creating three tables Register,Posts and Friends. Once the Database is Created with the Name HeartBeatDB you can execute the below script to create tables required for social networking website
USE [HeartBeatDB]
GO
/****** Object:  Table [dbo].[Register]  ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO


CREATE TABLE [dbo].[Register](
 [RegisterId] [int] IDENTITY(1,1) NOT NULL,
 [EmailId] [varchar](50) NULL,
 [Pwd] [varchar](50) NULL,
 [Gender] [varchar](10) NULL,
 [DOB] [varchar](10) NULL,
 [AboutMe] [varchar](500) NULL,
 [Country] [varchar](30) NULL,
 [ProfilePic] [image] NULL,
 [Name] [varchar](100) NULL,
PRIMARY KEY CLUSTERED 
(
 [RegisterId] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, 
IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, 
ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO




/****** Object:  Table [dbo].[Posts]   ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO


CREATE TABLE [dbo].[Posts](
 [PostId] [int] IDENTITY(1,1) NOT NULL,
 [FromId] [int] NULL,
 [ToId] [int] NULL,
 [Post] [varchar](1000) NULL,
 [PostDate] [varchar](50) NULL,
PRIMARY KEY CLUSTERED 
(
 [PostId] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, 
IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, 
ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO




/****** Object:  Table [dbo].[Friends]   ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO



CREATE TABLE [dbo].[Friends](
 [FriendshipId] [int] IDENTITY(1,1) NOT NULL,
 [MyId] [int] NULL,
 [FriendId] [int] NULL,
 [Status] [int] NULL,
 [MeOnline] [int] NULL,
 [FriendOnline] [int] NULL,
 [PingStatus] [int] NULL
) ON [PRIMARY]
GO

        
        
After Executing this script three tables will be created
a.Register Table- it will store all the information provided by the user during registration
b.Posts Table - it will store all the posts written by the user on his wall or on his friends wall
c.Friends Table - it will store all the friendship status about the friend requests send  

Images used in Social Networking Website project


Images used in Social Networking Website

This are the Images that we have used in our Social Networking Project.
You can save all this images inside images folder and then after refreshing the solution explorer all this images will be available in your project

It is good image and can be used where we want to show the administrator of any website.We have so far not used this image file in this project


It is a GiF file of an dancing boy which is cool and it shows Enthusiasum and is Energetic and also it is eye catching.This Image can be used used in almost any project


It is a Friends Icon Image.It can be used along side a label to represent friendlist or Friends of any user or a group of people.It is good icon


This is another Friends icon with two user images merged with each other.It is colorful and can be used where ever needed


This is another Friends Icon image in PNG format.The color theme of this icon is like facbook and it can also be used to represent friends or groups for a social networking website


It is a logo for our Social networking website called heartbeat.As we have kept the name of our social networking website as hearbeat.This logo clearly shows the heart with its beats

It is a PNG format Add as Friend button which can be used for sending friend request.The color theme of this button is similar to facebook

This is another logo for our heart beat project.Its a full red heart with some beats in it.It is cool and can be used on the home page of this project.


This is also logo for our hearbeat social app.The only different thing about this logo is that it is animated and it keeps changing its color.It has different colors such as green,red,pink and grey.The changing color effect and the heartbeat coming out of the heart makes it our choice and we have put this logo in our live demo of HeartBeat


This is an animated loading gif image.we have used this image on our wall and latest updates user control.When any user enters something on his or her wall.This loading effect comes and with any postback the post is updated


This is Messages icon and it can be used along with the users inbox messages and it can also be set as a background and above it we can show the inbox messages in red link just like facebook

This is another messages icon.it is is png format it can also be used for messages notification for any user account

This Image is an notification icon which can be used to show the notifications or any kind of alerts that a user is suppose to see.


This is the default profile picture if any user has not uploaded its profile picture then we can set this picture as its profile picture.But the coding for setting the default profile picture is not done in this project so far

It is a green online icon.It is displayed when a user is online.It is Indication that a particular user is online.Online chatting or one to one chatting is not yet implemented in this project so far.it will be implemented in our next project of online chatting which we will be developing very sooooon.
This is the messenger icon of facebook.The same messenger icon that we all have on our facebook account.
This is the Friend Request icon of facebook.The same Friend Request icon that we all have on our facebook account.
This is the Globe or Notification icon of facebook.The same Globe or Notification icon that we all have on our facebook account.     

Website Project for Social Networking in Asp.Net Csharp


Creating New Website Project for Social Networking in Asp.Net C#

Step 1:Open VisualStudio

  1. Open Visual Studio 2010 or Visual studio 2008 or Visual Studio 2005 which ever version of visual studio you have.
  2.  After Opening visual studio Click on File Menu and select New and then select website as shown below


Step 2:Select Your Website Location,.Net Framework,Programming Language

  1. After Clicking on Website option a New Website Box will open.
  2. In this Dialog box Select Your Appropriate Options.We have selected Asp.Net Empty Website
  3. Here we have selected .Net framework 4.0,Visual csharp,Website Location as E drive.You can change website location by clicking on browse button
  4. After Selecting all options click on OK


Step 3:Empty Project with web.config File

  1. Now you have created an empty project with all those options as mentioned in above steps.if you check the solution explorer then you will find that it is an empty project with only a webconfig file
  2. If Solution Explorer is not visible to you then you can make it visible by going to View Menu and then selecting Solution Explorer.
  3. You can also make it visible by using the shortcut key Clt+Alt+L.It will look as shown in the below screen shot
    

Step 4:Database Connectivity File and Alert User File Creation

  1. In this step we will be creating two common files Database.cs and Alert.cs
  2. Database.cs is a common file that is used to interact with database for insert update deleting and selecting records
  3. So right click on Project Name and select Add New Item.
  • Add New Item will open a dialog box from where we can select what we have to add.Here we have to select C# class files and name it as Database.cs as shown below




  • After Clicking on Add Button it will prompt you with a window with a message shown below.It means that do we want to place newly created .cs file in AppCode Folder or Not
  • Clicking on Yes Option will create a AppCode Folder with Database.cs File.
  • Similarly create another file Alert.cs following the same steps.Finally we have AppCodeFolder Folder with two Files Database.cs and Alert.cs Class files





Step 5:Make Controls Folder and images Folder
  • Right Click on Project Name and Add New Folder.Make two folders one as Controls and other as images
  • So right click on Controls Folder and select Add New Item.

  • From the Add New Item Dialog box select add user controls and a single Image Handler
  • Finally Inside you should have this many User controls and One ImageHandler as shown below




Step 6:Adding Master Pages HomeMaster and Profile Master

  1. Now right click on Project Name and select Add New Item and Add two Master Pages Name One as HomeMaster.master and other as ProfileMaster.master
  2. While Adding Master pages there are two check boxes at bottom right.Select Place Code in Different File and Unselect Select Master pages.By default you will have this two options
  3. Now we have two master pages HomeMaster.master and ProfileMaster.master


Step 7:Adding Child Pages Under HomeMaster.master masterpage
Now right click on Project Name and select Add New Item and Add Default.aspx page and select the master page as HomeMaster.master






Step 8:Adding Child Pages Under ProfileMaster.master masterpage
Now right click on Project Name and select Add New Item and Add Main.aspx page,Search.aspx page and Friends.aspx page and AboutMe.aspx page and select the master page as ProfileMaster.master


Step9:Add Webservice for AutoComplete Extender and Search Suggestions
Now right click on Project Name and select Add New Item and then it will add a web service on root level and its .cs file in appcode folder


Step10:Final Folder Structure for Social networking website
Finally After adding all the pages and making an emtpy project with all images you are ready to go.
You should also install Ajax Control toolkit which will add AjaxControlToolKit.dll reference in your bin folder


Ok Great.Let Begin Our Journey towards Code