<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Login_Form.aspx.cs" Inherits="ajax_control" Debug="true"%>
<%@ Register assembly="AjaxControlToolkit" namespace="AjaxControlToolkit" tagprefix="cc1" %>
<!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>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<div>
<asp:UpdatePanel id="pan" runat="server">
<ContentTemplate>
<asp:Panel ID="pan_1" runat="server">
<asp:Label ID="lblname" runat="server" Text="UserName :"></asp:Label>
<asp:TextBox ID="txtaccountid" runat="server" MaxLength="25" ValidationGroup="Login_valid"></asp:TextBox>
<asp:RequiredFieldValidator ID="rfv_accountid" runat="server"
ErrorMessage="Please Enter Username" ControlToValidate="txtaccountid"
SetFocusOnError="True" ValidationGroup="Login_valid"></asp:RequiredFieldValidator>
<cc1:ValidatorCalloutExtender ID="ValidatorCalloutExtender1" runat="server" TargetControlID="rfv_accountid" >
</cc1:ValidatorCalloutExtender>
<br />
<asp:Label ID="lblpassword" runat="server" Text="Password" ></asp:Label>
<asp:TextBox ID="txtpassword" runat="server" MaxLength="25" TextMode="Password" ValidationGroup="Login_valid"></asp:TextBox>
<asp:RequiredFieldValidator ID="rfv_password" runat="server"
ErrorMessage="Please Enter Password" ControlToValidate="txtpassword"
Display="None" SetFocusOnError="True" ValidationGroup="Login_valid"></asp:RequiredFieldValidator>
<cc1:ValidatorCalloutExtender ID="ValidatorCalloutExtender2" runat="server" TargetControlID ="rfv_password">
</cc1:ValidatorCalloutExtender>
<br />
<asp:Button ID="Btnenter" Text="Submit" runat="server" AccessKey="S"
Font-Bold="true" Font-Size="Medium" onclick="Btnenter_Click" ValidationGroup="Login_valid"></asp:Button>
<br />
<asp:CustomValidator ID="CVC" runat="server"
ErrorMessage="Invalid Username or Password, Please Try Again." onservervalidate="CVC_ServerValidate" ValidationGroup="Login_valid"
SetFocusOnError="True"></asp:CustomValidator>
</asp:Panel>
</ContentTemplate>
</asp:UpdatePanel>
</div>
</form>
</body>
</html>
code page
=======
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Web.SessionState;
using AjaxControlToolkit;
using Laxmi.ABL;
using Laxmi.BAL;
using Laxmi.DAL;
public partial class ajax_control : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
//Session["account_name"] = "Laxmi Main"; //Admin name
//Session["account_id"] = "A000001"; //Admin Login ID
//Session["usertype"] = "SA"; //USer type
Session["tree_id"] = "1";
//Session["login_id"] = "99"; //Admin Identity id
//Session["UserRole"]=param value -> param values1
}
protected void Btnenter_Click(object sender, EventArgs e)
{
//AdminBaseMembers GetUserVar = new AdminBaseMembers(); // here created adminbase class obj
//GetUserVar.Account_ID = txtaccountid.Text.Trim();
//GetUserVar.password = txtpassword.Text.Trim();
//GetUserVar.Session_ID = Session["tree_id"].ToString();
//// below code for otherthan admin
//AdminMembers user = new AdminMembers();
//SqlDataReader myuser = user.User_Name(GetUserVar);
//myuser.Read();
//if (myuser.HasRows == true) // is there any row exist
//{
// Session["account_name"] = myuser["Account_Name"].ToString();
// Session["account_id"] = myuser["account_id"].ToString();
// Session["usertype"] = myuser["Isuser"].ToString();
// Session["login_id"] = Convert.ToInt32(myuser["id"]);
// myuser.Close();
// string sqlrole;
// sqlrole = "select Param_Values.PName,Param_Values.PValue1 from Param_Values,Param_Table " +
// " where Param_Values.param_id=Param_Table.id and Param_Table.Param_Name='UserRoles' and Param_Values.PName='U' ";
// SqlConnection sqlcon = new SqlConnection(ConfigurationManager.ConnectionStrin gs["laxmi"].ConnectionString);
// sqlcon.Open();
// SqlCommand sqlcmd = new SqlCommand(sqlrole, sqlcon);
// SqlDataReader sqldr = sqlcmd.ExecuteReader();
// sqldr.Read();
// if (sqldr.HasRows == true)
// {
// Session["UserRole"] = sqldr["Pvalue1"].ToString();
// }
// sqldr.Close();
// Response.Redirect("sessionpage.aspx");
// /// end here other userlogin
//}
////else
//// {
//// for login by admin
////if (existuser ="yes")
//// == below cod for admin_check ==
//AdminBaseMembers Get_Admin = new AdminBaseMembers(); // here created adminbase class obj
//Get_Admin.Account_ID = txtaccountid.Text.Trim(); // from account_master
//AdminMembers Admin_Obj = new AdminMembers();
//SqlDataReader Admindr = Admin_Obj.User_Admin(Get_Admin);
//Admindr.Read();
//if (Admindr.HasRows == true) // is there any row exist
//{
// Session["account_name"] = Admindr["Account_Name"].ToString();
// Session["account_id"] = Admindr["account_id"].ToString();
// Session["usertype"] = Admindr["Isuser"].ToString();
// Session["login_id"] = Convert.ToInt32(Admindr["id"]);
// Admindr.Close();
// AdminMembers Admin_Obj_1 = new AdminMembers();
// Get_Admin.password = txtpassword.Text.Trim(); // from Param_table.pvalue1
// SqlDataReader Adminps = Admin_Obj_1.User_adminpass(Get_Admin);
// Adminps.Read();
// if (Adminps.HasRows == true)
// {
// Adminps.Close();
// Response.Redirect("Admin_Login.aspx");
// }
//}
}
// this is a custom validator control tocheck username or password is correct or not
protected void CVC_ServerValidate(object source, ServerValidateEventArgs args)
{
//
AdminBaseMembers GetUserVar = new AdminBaseMembers(); // here created adminbase class obj
GetUserVar.Account_ID = txtaccountid.Text.Trim();
GetUserVar.password = txtpassword.Text.Trim();
GetUserVar.Session_ID = Session["tree_id"].ToString();
AdminMembers user = new AdminMembers();
SqlDataReader userdr = user.User_Name(GetUserVar);
//string idsession = Session["tree_id"].ToString();
//SqlConnection mysql = new SqlConnection(ConfigurationManager.ConnectionStrin gs["laxmi"].ConnectionString);
//mysql.Open();
//string sqlqry = "Select * from laxmivarsha.Account_Master where Account_ID = '" + txtaccountid.Text + "' And " +
//" password = '" + txtpassword.Text + " ' and Flag = 'A' and Tree_id = '" + idsession + "' ";
//SqlCommand sqlcmd = new SqlCommand();
//sqlcmd.Connection = mysql;
//sqlcmd.CommandText = sqlqry;
//sqlcmd.CommandType = CommandType.Text;
//SqlDataReader userdr;
userdr.Read();
if (userdr.HasRows == false)
{
args.IsValid = false;
}
if (userdr.HasRows == true)
{
Session["Account_Name"] = userdr["Account_Name"].ToString();
userdr.Close();
args.IsValid = true;
Response.Redirect("Custom_Ok.aspx");
// else
// {
// }
}
// else
//string adminsession = Session["tree_id"].ToString();
//SqlConnection adminsql = new SqlConnection(ConfigurationManager.ConnectionStrin gs["laxmi"].ConnectionString);
//adminsql.Open();
//string adminqry = "Select * from laxmivarsha.Account_Master where Account_ID = '" + txtaccountid.Text + "' ";
//SqlCommand admincmd = new SqlCommand();
//sqlcmd.Connection = adminsql;
//sqlcmd.CommandText = adminqry;
//sqlcmd.CommandType = CommandType.Text;
//SqlDataReader admindr ; // = sqlcmd.ExecuteReader();
AdminBaseMembers Get_Admin = new AdminBaseMembers(); // here created adminbase class obj
Get_Admin.Account_ID = txtaccountid.Text.Trim(); // from account_master
AdminMembers Admin_Obj = new AdminMembers();
SqlDataReader admindr = Admin_Obj.User_Admin(Get_Admin);
admindr.Read();
if (admindr.HasRows == true)
{
Session["Account_Name"] = admindr["Account_Name"].ToString();
admindr.Close();
//SqlConnection adminsqlcon = new SqlConnection(ConfigurationManager.ConnectionStrin gs["laxmi"].ConnectionString);
//adminsqlcon.Open();
//string adminpassqry = "select Param_Values.PName,Param_Values.PValue1 from Param_Values,Param_Table where Param_Values.param_id=Param_Table.id and Param_Table.Param_Name='AdminAuthenticate' and Param_Values.PName='AllUserPass' ";
// "select Param_Values.PName,Param_Values.PValue1 from Param_Values,Param_Table where Param_Values.param_id=Param_Table.id and Param_Table.Param_Name='AdminAuthenticate' and Param_Values.PName='AllUserPass' ";
//SqlCommand adminpasscmd = new SqlCommand();
//sqlcmd.Connection = adminsqlcon;
//sqlcmd.CommandText = adminpassqry;
//sqlcmd.CommandType = CommandType.Text;
//SqlDataReader adminpassdr; //= sqlcmd.ExecuteReader();
AdminMembers Admin_Obj_1 = new AdminMembers();
Get_Admin.password = txtpassword.Text.Trim(); // from Param_table.pvalue1
SqlDataReader adminpassdr = Admin_Obj_1.User_adminpass(Get_Admin);
adminpassdr.Read();
if (adminpassdr.HasRows == true)
{
if (txtpassword.Text.Trim() == adminpassdr["pvalue1"].ToString())
{
args.IsValid = true;
adminpassdr.Close();
Response.Redirect("Custom_Ok.aspx");
}
}
}
else
{
args.IsValid = false;
// Response.Redirect("Custom_Ok.aspx");
//Response.Redirect("Invaliduser.aspx");
}
}
}
by mahendra.developer@yahoo.com, india