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

    }
}



5 comments:

  1. Sir can you please send the whole project to my mail praveena438@gmail.com

    ReplyDelete
  2. The login button click is not working. please replay

    ReplyDelete
  3. dt = Database.GetData(query);
    can you please say what is Database in this line im getting an error please sir

    ReplyDelete
  4. please send the full project to my mail id dollysinha28@gmail.com

    ReplyDelete