Login / Sign up using WEB METHOD
/*ADMIN MASTER for Project*/
<%@ Master Language="C#" AutoEventWireup="true" CodeBehind="Admin.master.cs" Inherits="PictureGallery.Admin" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" style="background-image: URL(../Image/Dash_Background.jpg);">
<head runat="server">
<link href="Css/DashBoardCss.css" rel="stylesheet" />
<title>Picture Gallery</title>
<asp:ContentPlaceHolder ID="head" runat="server">
</asp:ContentPlaceHolder>
<style>
.xyz {
float: right;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
<table style="width: 100%">
<tr>
<td>
<div class="xyz">
<ul>
<li><a class="active" href="#home">Home</a>
</li>
<li><a href="#news">Gallery</a>
</li>
<li><a href="#My Profile" id="openDialog" >My Profile</a>
</li>
<li><a href="#about">About Us</a>
</li>
<li><a href="login.aspx">Log Out</a>
</li>
</ul>
</div>
</td>
</tr>
<tr>
<td>
<asp:ContentPlaceHolder ID="ContentPlaceHolder" runat="server">
</asp:ContentPlaceHolder>
</td>
</tr>
</table>
</div>
</form>
</body>
</html>
LOGIN.ASPX PAGE
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="login.aspx.cs" Inherits="PictureGallery.login" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" class="cover_pic">
<head runat="server">
<title>Picture Gallery</title>
<link href="Css/loginPage.css" rel="stylesheet" />
<style>
.textColor {
color: green;
}
</style>
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css" />
<script>
//function NewUserPopup() {
// var url = "NewUser.aspx";
// newwindow = window.open(url, 'name', 'width=400, height=320 left=400 top=300');
// if (window.focus) { newwindow.focus() }
//}
function fnValidate() {
var Name = document.getElementById("txtName").value;
var Email = document.getElementById("txtEmail").value;
var Password = document.getElementById("txtPass").value;
var DOB = document.getElementById("txtDOB").value;
var Gender = $('#radiogender input:checked').val();
var Address = document.getElementById("txtAddress").value;
var Mobile = document.getElementById("txtMobile").value;
if (Name == "") {
alert("Enter name");
document.getElementById("txtName").focus();
return false;
}
if (Email == "") {
alert("Enter Email");
document.getElementById("txtEmail").focus();
return false;
} if (Password == "") {
alert("Enter Password");
document.getElementById("txtPass").focus();
return false;
}
if (Gender == undefined) {
alert("Enter Gender");
$('#radiogender input:checked').focus();
return false;
} if (DOB == "") {
alert("Enter DOB");
document.getElementById("txtDOB").focus();
return false;
}
if (Address == "") {
alert("Enter Address");
document.getElementById("txtAddress").focus();
return false;
} if (Mobile == "") {
alert("Enter Mobile");
document.getElementById("txtMobile").focus();
return false;
}
save(Name, Email, Password, DOB, Gender, Address, Mobile);
}
/*Ajax function for Insert Data*/
function save(Name, Email, Password, DOB, Gender, Address, Mobile) {
$.ajax({
type: 'POST',
contentType: "application/json; charset=utf-8",
url: 'login.aspx/Insert_Data',
data: "{'Name':'" + Name + "','Email':'" + Email + "','Password':'" + Password + "','DOB':'" + DOB + "','Gender':'" + Gender + "','Address':'" + Address + "','Mobile':'" + Mobile + "'}",
async: false,
success: function (response) {
alert("Record saved successfully..!!");
},
error: function () {
alert("Error");
}
});
}
$(function () {
$("#dialogBox").dialog({
autoOpen: false, modal: true,
show: {
effect: "blind",
duration: 1000
},
hide: {
effect: "explode",
duration: 1000
}
});
$("#openDialog").on("click", function () {
$("#dialogBox").dialog("open");
});
});
function closeDialog() {
$("#dialogBox").dialog("close");
}
</script>
<style>
.ui-dialog {
height: auto;
width: 400px !important;
}
a {
color: blue !important;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div class="login_div">
<table class="login_form">
<tr>
<td colspan="2" style="color: red">
<asp:Label ID="lblMsg" runat="server"></asp:Label>
</td>
</tr>
<tr>
<td class="textColor">User Name
</td>
<td>
<asp:TextBox ID="txtUserName" runat="server" CssClass="UserName"></asp:TextBox>
</td>
</tr>
<tr>
<td class="textColor">Password
</td>
<td>
<asp:TextBox ID="txtPassword" TextMode="Password" runat="server" CssClass="password"></asp:TextBox>
</td>
</tr>
<tr>
<td colspan="2" style="text-align: center">
<asp:Button ID="btnLogin" runat="server" Text="login" CssClass="buttoncss" OnClick="btnLogin_Click" />
</td>
</tr>
<tr>
<td colspan="2" style="text-align: center">
<a href="#" id="openDialog">NewUser</a>
<%-- <asp:LinkButton ID="LinkButton1" runat="server" Text="New User1" CssClass="dialog"></asp:LinkButton>
<asp:LinkButton ID="lnkButton" runat="server" Text="New User" OnClientClick="NewUserPopup();"></asp:LinkButton>--%>
</td>
</tr>
</table>
</div>
<div id="dialogBox">
<fieldset>
<legend style="color: darkblue; font-weight:bold">New User Signup</legend>
<asp:Table ID="Table1" runat="server">
<asp:TableRow>
<asp:TableCell ColumnSpan="2" HorizontalAlign="Center">
<asp:Label ID="Label1" runat="server"></asp:Label>
</asp:TableCell>
</asp:TableRow>
<asp:TableRow>
<asp:TableCell>
Name
</asp:TableCell>
<asp:TableCell>
<asp:TextBox ID="txtName" runat="server" CssClass="textboxstyle"></asp:TextBox>
</asp:TableCell>
</asp:TableRow>
<asp:TableRow>
<asp:TableCell>
User Id
</asp:TableCell>
<asp:TableCell>
<asp:TextBox ID="txtEmail" runat="server" CssClass="textboxstyle"></asp:TextBox>
</asp:TableCell>
</asp:TableRow>
<asp:TableRow>
<asp:TableCell>
Password
</asp:TableCell>
<asp:TableCell>
<asp:TextBox ID="txtPass" runat="server" CssClass="textboxstyle"></asp:TextBox>
</asp:TableCell>
</asp:TableRow>
<asp:TableRow>
<asp:TableCell>
Gender
</asp:TableCell>
<asp:TableCell>
<asp:RadioButtonList ID="radiogender" runat="server" RepeatDirection="Horizontal">
<asp:ListItem Text="Male" Value="Male"></asp:ListItem>
<asp:ListItem Text="Female" Value="Female"></asp:ListItem>
</asp:RadioButtonList>
</asp:TableCell>
</asp:TableRow>
<asp:TableRow>
<asp:TableCell>
Date Of Birth
</asp:TableCell>
<asp:TableCell>
<asp:TextBox ID="txtDOB" runat="server" CssClass="textboxstyle" TextMode="Date"></asp:TextBox>
</asp:TableCell>
</asp:TableRow>
<asp:TableRow>
<asp:TableCell>
Address
</asp:TableCell>
<asp:TableCell>
<asp:TextBox ID="txtAddress" runat="server" CssClass="textboxstyle" TextMode="MultiLine" Height="50px"></asp:TextBox>
</asp:TableCell>
</asp:TableRow>
<asp:TableRow>
<asp:TableCell>
Mobile
</asp:TableCell>
<asp:TableCell>
<asp:TextBox ID="txtMobile" runat="server" CssClass="textboxstyle"></asp:TextBox>
</asp:TableCell>
</asp:TableRow>
<asp:TableRow>
<asp:TableCell ColumnSpan="2" HorizontalAlign="Center">
<asp:Button ID="btnSave" Text="Save" runat="server" CssClass="buttoncss" OnClientClick="return fnValidate();" />
<asp:Button ID="btnCancel" Text="Cancel" runat="server" OnClientClick="closeDialog();" CssClass="buttoncss" />
</asp:TableCell>
</asp:TableRow>
</asp:Table>
</fieldset>
</div>
</form>
</body>
</html>
LOGIN.ASPX.CS PAGE
sing MySql.Data.MySqlClient;
using PictureGallery.BL;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace PictureGallery
{
public partial class login : System.Web.UI.Page
{
MySQLQuery obj = new MySQLQuery();
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnLogin_Click(object sender, EventArgs e)
{
string query = "select User_Id from user_info_mst where User_Email_ID='" + txtUserName.Text + "' and User_Password='" + txtPassword.Text + "';";
DataSet i = obj.readData(query);
DataTable dt = new DataTable();
dt = i.Tables[0];
if (dt.Rows.Count> 0)
{
Session["User_Id"] = dt.Rows[0]["User_Id"].ToString();
Response.Redirect("HomePage.aspx");
}
else {
lblMsg.Text = "Invalid User Name or Password, Try Again!!!!!";
}
}
/* DATA Insert Using web Method*/
[WebMethod]
public static string Insert_Data(string Name, string Email, string Password, string DOB, string Gender, string Address, string Mobile)
{
MySqlConnection con = new MySqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
try
{
con.Open();
MySqlCommand cmd = new MySqlCommand("insert into user_info_mst (UserName,User_Email_ID,User_Password,Gender,DOB,Address,Mobile) values ('" + Name + "','" + Email + "','" + Password + "','" + Gender + "','" + DOB + "','" + Address + "'," + Mobile + ")", con);
cmd.ExecuteNonQuery();
con.Close();
return "Success";
}
catch (Exception e)
{
return "failure";
}
}
}
}
/*BL which inherit to perform Mysql action*/
using MySql.Data.MySqlClient;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
namespace PictureGallery.BL
{
public class MySQLQuery
{
MySqlConnection con = new MySqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
public int ExecutQuery(string query)
{
con.Open();
MySqlCommand cmd = new MySqlCommand(query, con);
int i = cmd.ExecuteNonQuery();
con.Close();
return i;
}
public DataSet readData(string query)
{
con.Open();
MySqlCommand cmd = new MySqlCommand(query, con);
MySqlDataAdapter da = new MySqlDataAdapter(cmd);
DataSet dt=new DataSet ();
da.Fill(dt);
con.Close();
return dt;
}
}
}
/*CSS for Login page*/
body {
}
.login_div {
border: solid;
border-color: green;
width: 45%;
margin-left: 55% ! important;
margin-top: 300px;
height: 200px;
border-radius: 25px;
background-image: Url(../Image/pic2.jpg);
background-size: 400px 200px;
}
.login_form {
margin-top: 10%;
margin-left: 25%;
}
.cover_pic {
background-image: Url(../Image/pic5.jpg);
background-size: 100% 1000px;
}
.UserName {
background-image: Url(../Image/userName.jpg);
background-size: 30px 20px;
background-repeat: no-repeat;
background-position: right;
}
.password {
background-image: Url(../Image/password.jpg);
background-size: 30px 20px;
background-repeat: no-repeat;
background-position: right;
}
.buttoncss {
width: 75px;
border-radius: 6px;
border-color: green;
}
/*Dashbord css*/
body {
}
ul {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
background-color: inherit;
}
li {
float: left;
}
li a {
display: block;
color: white;
text-align: center;
padding: 14px 16px;
text-decoration: none;
}
li Button:a {
background-color: purple;
}
/*common css*/
.buttoncss {
width: 75px;
border-radius: 6px;
border-color: green;
}
.textboxstyle {
height:15px;
color:gray;
font-size:small;
width:225px;
}
table tr td {
color:gray;
}
.div_Background {
background: darkgreen;
}
HOME.ASPX PAGE
<%@ Page Title="" Language="C#" MasterPageFile="~/Admin.Master" AutoEventWireup="true" CodeBehind="HomePage.aspx.cs" Inherits="PictureGallery.HomePage" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css" />
<script>
/*Function for open dialog box using JQUERY*/
$(function () {
$("#UserInfo").dialog({
autoOpen: false, modal: true,
show: {
effect: "blind",
duration: 1000
},
hide: {
effect: "explode",
duration: 1000
}
});
$("#openDialog").on("click", function () {
var getDate = fnGETEmpDetails();
$("#UserInfo").dialog("open");
});
});
/*Function for bind data using ajax*/
function fnGETEmpDetails() {
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "HomePage.aspx/getDetails",
data: "{}",
dataType: "json",
success: achivedata,
error: function (result) {
alert("Error");
}
});
}
function achivedata(e) {
var datalist = e.d;
document.getElementById('<%=lblName.ClientID%>').innerText = datalist[0].empName;
document.getElementById('<%=lblUserId.ClientID%>').innerText = datalist[0].Email;
document.getElementById('<%=lblGender.ClientID%>').innerText = datalist[0].Gender;
document.getElementById('<%=lblDOB.ClientID%>').innerText = datalist[0].DOB;
document.getElementById('<%=lblAddress.ClientID%>').innerText = datalist[0].Address;
document.getElementById('<%=lblMobile.ClientID%>').innerText = datalist[0].Mobile;
}
function closeDialog() {
$("#UserInfo").dialog("close");
}
</script>
<style>
.ui-dialog {
height: auto;
width: 400px !important;
top: 60px !important;
margin-left: 60%;
}
</style>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder" runat="server">
<div id="UserInfo">
<fieldset>
<legend style="color: darkblue; font-weight: bold">My Profile</legend>
<asp:Table ID="Table1" runat="server">
<asp:TableRow>
<asp:TableCell>
Name
</asp:TableCell>
<asp:TableCell>
<asp:Label ID="lblName" runat="server"></asp:Label>
</asp:TableCell>
</asp:TableRow>
<asp:TableRow>
<asp:TableCell>
User Id
</asp:TableCell>
<asp:TableCell>
<asp:Label ID="lblUserId" runat="server"></asp:Label>
</asp:TableCell>
</asp:TableRow>
<asp:TableRow>
<asp:TableCell>
Gender
</asp:TableCell>
<asp:TableCell>
<asp:Label ID="lblGender" runat="server"></asp:Label>
</asp:TableCell>
</asp:TableRow>
<asp:TableRow>
<asp:TableCell>
Date Of Birth
</asp:TableCell>
<asp:TableCell>
<asp:Label ID="lblDOB" runat="server"></asp:Label>
</asp:TableCell>
</asp:TableRow>
<asp:TableRow>
<asp:TableCell>
Address
</asp:TableCell>
<asp:TableCell>
<asp:Label ID="lblAddress" runat="server"></asp:Label>
</asp:TableCell>
</asp:TableRow>
<asp:TableRow>
<asp:TableCell>
Mobile
</asp:TableCell>
<asp:TableCell>
<asp:Label ID="lblMobile" runat="server" ></asp:Label>
</asp:TableCell>
</asp:TableRow>
</asp:Table>
</fieldset>
</div>
</asp:Content>
HOME.ASPX.CS PAGE
(Data bind using Web Method)
using MySql.Data.MySqlClient;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace PictureGallery
{
public partial class HomePage : System.Web.UI.Page
{
MySqlConnection con = new MySqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
public static string userid = "";
protected void Page_Load(object sender, EventArgs e)
{
userid= Session["User_Id"].ToString();
}
/*Web Method Data bind and return as a Array*/
public class employee
{
public string empName { get; set; }
public string Email { get; set; }
public string DOB { get; set; }
public string Gender { get; set; }
public string Address { get; set; }
public string Mobile { get; set; }
}
[WebMethod]
public static employee[] getDetails()
{
List<employee> listobjEmp = new List<employee>();
MySqlConnection con = new MySqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
string qry = "select UserName,User_Email_ID,Gender,date_format(DOB,'%d-%b-%Y')as DOB,Address,Mobile from user_info_mst where User_Id=" + userid;
con.Open();
MySqlCommand cmd = new MySqlCommand(qry, con);
MySqlDataReader read = cmd.ExecuteReader();
employee empObj = new employee();
while (read.Read())
{
empObj.empName = read["UserName"].ToString();
empObj.Email = read["User_Email_ID"].ToString();
empObj.Gender = read["Gender"].ToString();
empObj.DOB = read["DOB"].ToString();
empObj.Address = read["Address"].ToString();
empObj.Mobile = read["Mobile"].ToString();
}
listobjEmp.Add(empObj);
con.Close();
return listobjEmp.ToArray();
}
}
}