Tuesday 27 November 2012

simple login form in asp.net

In aspx page:

<div id="container">
    <form id="form1" runat="server">
    <div>
    <div class="head">Login Here!!!</div><br />
    <div>
        <label class="lab">email</label><asp:TextBox ID="TextBox1" runat="server" CssClass="textarea"></asp:TextBox>
        <br /><br />
        <label class="lab">password</label><asp:TextBox ID="TextBox2" runat="server" CssClass="textarea"></asp:TextBox>
        <br /><br />
        <div class="but"><asp:Button ID="Button1" runat="server" Text="Button"
                CssClass="button" onclick="Button1_Click" /> 
            <asp:Label ID="lbl" runat="server"></asp:Label>
        </div>
    </div>
    </div>
    </form>
    </div>

IN CS PAGE

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Configuration;
using System.Data;

public partial class Default3 : System.Web.UI.Page
{
    static string strconn = ConfigurationManager.ConnectionStrings["reg"].ConnectionString;
    SqlConnection con = new SqlConnection(strconn);
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {

      
        con.Open();
        SqlCommand cmdd = new SqlCommand("select * from tb_reg where email='" + TextBox1.Text + "' AND password='" + TextBox2.Text + "'",con);  
        SqlDataAdapter da = new SqlDataAdapter(cmdd);
        DataTable dt = new DataTable();
        da.Fill(dt);
        if (dt.Rows.Count > 0)
        {
            Session["user"] = TextBox1.Text;
            Response.Redirect("drop.aspx");   
        }
        else
        {
            lbl.Text = "login failure";
        }
        con.Close();
    }
}


No comments:

Post a Comment