Profile Picture in Social networking Website using asp.net csharp



Profile Picture in Social networking Website using asp.net csharp



  1. Profile Picture is the heart of all social netoworking websites like facebook,twitter,google plus.
  2. For our Social Networking site HeartBeat we have created a user control to show the left side menu along with the profile picture

ProfilePic.ascx Code:

  1. Open ProfilePic.ascx User Control Which You have created in Controls Folder.
  2. In the Source of ProfilePic.ascx user control you can add the following piece of code given below.
  3. In Profile picture user control we have created a tabular structure and dragged dropped one datalist to show the profile picture which is converted into bytes using handler,also we have dragged dropped two link buttons for aboutme and friends.
  4. We have also created one label to show the user name along with profile picture


<%@ Control Language="C#" AutoEventWireup="true" 
CodeFile="ProfilePic.ascx.cs" Inherits="Controls_ProfilePic" %>
<style type="text/css">
    .ProfilePic
    {
        width: 171px;
    }
</style>
<table align="center" class="ProfilePic">
    <tr>
        <td align="center">
            <asp:DataList ID="dlProfile" runat="server" BorderColor="Black" 
            BorderStyle="Ridge"
                BorderWidth="0px" Visible="false" Width="60px">
                <ItemTemplate>
                    <table align="center" style="width: 100%">
                        <tr>
                            <td>
                            <asp:ImageButton ID="ImagePhoto" runat="server"
                             BorderColor="Black" BorderStyle="Ridge"
                             BorderWidth="1px" Height="170px"
                             ImageUrl='<%# "ImageHandler.ashx?RegisterId="+ Eval("RegisterId") %>'
                             Width="158px" />
                            </td>
                        </tr>
                    </table>
                </ItemTemplate>
            </asp:DataList>
        </td>
    </tr>
    <tr>
        <td align="center" style="border: 1px ridge #CCCCCC">
            <asp:LinkButton ID="btnAboutMe" runat="server" 
            OnClick="btnAboutMe_Click">AboutMe</asp:LinkButton>
        </td>
    </tr>
    <tr>
        <td align="center" style="border: 1px ridge #CCCCCC">
            <asp:LinkButton ID="btnFriends" runat="server" 
            OnClick="btnFriends_Click">Friends</asp:LinkButton>
        </td>
    </tr>
    <tr>
        <td align="center">
             
        </td>
    </tr>
    <tr>
        <td align="center">
             
        </td>
    </tr>
    <tr>
        <td align="center">
             
        </td>
    </tr>
    <tr>
        <td align="center">
             
        </td>
    </tr>
    <tr>
        <td align="center">
             
        </td>
    </tr>
    <tr>
        <td align="center">
             
        </td>
    </tr>
    <tr>
        <td align="center">
             
        </td>
    </tr>
    <tr>
        <td align="center">
             
        </td>
    </tr>
    <tr>
        <td align="center">
             
        </td>
    </tr>
    <tr>
        <td align="center">
             
        </td>
    </tr>
    <tr>
        <td align="center">
             
        </td>
    </tr>
    <tr>
        <td align="center">
             
        </td>
    </tr>
    <tr>
        <td align="center">
             
        </td>
    </tr>
    <tr>
        <td align="center">
             
        </td>
    </tr>
    <tr>
        <td align="center">
             
        </td>
    </tr>
    <tr>
        <td align="center">
             
        </td>
    </tr>
    <tr>
        <td align="center">
             
        </td>
    </tr>
    <tr>
        <td align="center">
             
        </td>
    </tr>
    <tr>
        <td align="center">
             
        </td>
    </tr>
</table>

     
Now Open the Code behind file of Friends User Control. In ProfilePic.ascx.cs file you can add the following piece of code given below.

ProfilePic.ascx.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;

    public partial class Controls_ProfilePic : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
       
          GetProfilePic();

        }

        private void GetProfilePic()
        {
            DataTable dt = new DataTable();
            string query = "select  *  from Register where RegisterId='" + Session["CurrentProfileId"] + "'";
            dt = Database.GetData(query);
            if (dt.Rows.Count > 0)
            {
                dlProfile.Visible = true;
                Session["Name"] = dt.Rows[0]["Name"];
                dlProfile.DataSource = dt;
                dlProfile.DataBind();
            }
            else
            {
            
            }
        }
        protected void btnAboutMe_Click(object sender, EventArgs e)
        {
            Response.Redirect("AboutMe.aspx");
        }
        protected void btnFriends_Click(object sender, EventArgs e)
        {
            Response.Redirect("Friends.aspx");
        }
 
    }
    

0 comments:

Post a Comment