Login Page Coding in ASP.NET
Write Coding in Default.aspx.cs
using System;
using System.Collections;
using System.Configuration;
using System.Data;
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.Data.SqlClient;
public partial class login : System.Web.UI.Page
{
string strcon = "Data Source=MADHU;Initial Catalog=image;Integrated Security=True";
//string NowDate = System.DateTime.Now.ToString();
SqlCommand cmd = new SqlCommand();
SqlCommand cmd1 = new SqlCommand();
DataTable dt = new DataTable();
SqlDataReader dr;
// SqlDataReader dr1;
DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter();
protected void Page_Load(object sender, EventArgs e)
{
Label32.Text = System.DateTime.Now.Date.ToString("dd/MM/yyyy");
TextBox1.Focus();
}
protected void Button1_Click(object sender, EventArgs e)
{
if (TextBox1.Text == "")
{
Label4.Visible = true;
}
else
{
Label4.Visible = false;
}
if (TextBox2.Text == "")
{
Label5.Visible = true;
}
else
{
Label5.Visible = false;
}
string admin = "";
SqlConnection con1 = new SqlConnection(strcon);
con1.Open();
if ((TextBox1.Text == "UserName") || (TextBox2.Text == "PassWord"))
{
SqlCommand cmd1 = new SqlCommand("select * from AspLoginForm where UserName = '" + TextBox1.Text + "' and PassWord = '" + TextBox2.Text + "'", con1);
cmd1.ExecuteNonQuery();
SqlDataReader dr1 = cmd1.ExecuteReader();
dr1.Read();
}
else
{
SqlConnection con = new SqlConnection(strcon);
con.Open();
cmd.Connection = con;
string Name = "";
cmd.CommandText = "select * from AspLoginForm where UserName = '" + TextBox1.Text + "' and Password = '" + TextBox2.Text + "'";
dr = cmd.ExecuteReader();
dr.Read();
if (dr.HasRows)
{
Name = dr.GetValue(0).ToString();
//string a = Session["WardName"].ToString();
Session["WardName"] = Name.ToString();
Response.Redirect("Default3.aspx");
}
else
{
Response.Write("");
TextBox1.Text = "";
TextBox2.Text = "";
}
dr.Close();
con.Close();
TextBox1.Focus();
}
}
protected void Button2_Click(object sender, EventArgs e)
{
TextBox1.Text = "";
TextBox2.Text = "";
}
protected void TextBox1_TextChanged(object sender, EventArgs e)
{
TextBox2.Focus();
}
protected void Button3_Click(object sender, EventArgs e)
{
Response.Redirect("Log-In.aspx");
}
}
No comments:
Post a Comment