Login

14
Login Design <%@ Page Title="" Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="login.aspx.cs" Inherits="login" %> <asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server"> </asp:Content> <asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server"> <center><table style="width: 230px"> <tr><td height="20" colspan="2" align="center"><asp:Label ID="Label1" ForeColor ="red" runat="server" Text="" Visible ="false"></asp:Label></td></tr> <tr><td align="right"><asp:Label ID="Label2" runat="server" Font-Bold="True" Style="position: static" Width="97px">Login Name :</asp:Label></td> <td>&nbsp;<asp:TextBox ID="txt_id" runat="server" Style="position: static" TabIndex="1" Width="145px" Height="25px"/> <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="txt_id" ErrorMessage="*"></asp:RequiredFieldValidator></td></tr> <tr><td align="right" class="style2"><asp:Label ID="Label4" runat="server">Password :</asp:Label></td> <td class="style3"> &nbsp;<asp:TextBox ID="txt_pwd" runat="server" TextMode="Password" TabIndex="2" Width="145px" Height="25px"/> <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="txt_pwd" ErrorMessage="*"></asp:RequiredFieldValidator></td></tr> <tr> <td align="right" class="style1"> <asp:Label ID="Label3" runat="server" Text="User Type :"></asp:Label></td> <td class="style1"> <asp:DropDownList ID="DropDownList1" runat="server" Width="145px" Height="25px"> <asp:ListItem>---Select---</asp:ListItem> <asp:ListItem>User</asp:ListItem> <asp:ListItem>Admin</asp:ListItem> <asp:ListItem>Teacher</asp:ListItem> </asp:DropDownList> </td> </tr>

description

Login Page Design

Transcript of Login

LoginDesign

Login Name : Password : ---Select--- User Admin Teacher

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

public partial class login : System.Web.UI.Page{ connection con=new connection(); protected void Page_Load(object sender, EventArgs e) {

} protected void Button2_Click(object sender, EventArgs e) { string st1 = txt_id.Text; string st2 = txt_pwd.Text; string st3 = DropDownList1.SelectedValue; con.open_connection(); string str = "select * from login where emaiid='" + txt_id.Text + "'"; SqlCommand cmd = new SqlCommand(str, con.con_pass()); SqlDataReader dr = cmd.ExecuteReader(); while (dr.Read()) { if (st1 == dr["emaiid"].ToString() && st2 == dr["password"].ToString() && st3 == "User") { Session["username"] = st1; Session["ctime"] = DateTime.Now.ToShortTimeString(); Response.Redirect("StudentProfile.aspx"); } else if (st1 == dr["emaiid"].ToString() && st2 == dr["password"].ToString() && st3 == "Admin") { Response.Redirect("userlist.aspx"); } else if (st1 == dr["emaiid"].ToString() && st2 == dr["password"].ToString() && st3 == "Teacher") { Session["username"] = st1; Response.Redirect("teacherProfile.aspx");

} else { ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('Check User Name and Password and contact for admin for approval')", true); } } con.close_connection(); } }

RegisterDesign

.style1 { width: 229px; }

Register Student

Sem1 Sem2 Sem3 Sem4 Sem5 Sem6 Sem7 Sem8 CSE Electrical Mechanical Civil A B C D

Backed Codeusing System;using System.Collections.Generic;using System.Web;using System.Web.UI;using System.Web.UI.WebControls;using System.Data;using System.Data.SqlClient;

public partial class register : System.Web.UI.Page{ connection con = new connection();

protected void Page_Load(object sender, EventArgs e) { fillid(); } public void fillid() { con.open_connection(); string str = "select * from registration order by userid"; SqlCommand cmd = new SqlCommand(str, con.con_pass()); SqlDataReader dr = cmd.ExecuteReader(); int i = 0; while (dr.Read()) { int a = 0; a = Convert.ToInt32(dr["userid"].ToString()); ViewState["sid"] = a.ToString(); i = i + 1; } if (i > 0) { int a = Convert.ToInt32(ViewState["sid"].ToString()); a = a + 1; txtID.Text = a.ToString(); } else txtID.Text ="101"; con.close_connection(); }

protected void Button1_Click1(object sender, EventArgs e) {

try { if (txtEmail.Text == string.Empty) { Label9.Visible = true; Label9.Text = "Email Must be Filled !!!!!"; } if (txtcEmail.Text == string.Empty) { Label9.Visible = true; Label9.Text = "Confirm Email Must be Filled !!!!!"; } else if (txtFname.Text == string.Empty) { Label9.Visible = true; Label9.Text = "First Name Must be Filled !!!!!"; }

else if (txtLName.Text == string.Empty) { Label9.Visible = true; Label9.Text = "Last Name Must be Filled !!!!!"; } else if (radGen.Text == string.Empty) { Label9.Visible = true; Label9.Text = "Gender Must Must be selected !!!!!"; } else if (txtPass.Text == string.Empty) { Label9.Visible = true; Label9.Text = "Password Must be filled !!!!!"; } else if (txtcPass.Text == string.Empty) { Label9.Visible = true; Label9.Text = "Confirm Password Must be filled !!!!!"; } else if (txtAdd.Text == string.Empty) { Label9.Visible = true; Label9.Text = "Address Must be filled !!!!!"; } else if (txtCity.Text == string.Empty) { Label9.Visible = true; Label9.Text = "City Must be filled !!!!!"; } else if (txtPone.Text == string.Empty) { Label9.Visible = true; Label9.Text = "Phone Must be filled !!!!!"; } else if (txtPostal.Text == string.Empty) { Label9.Visible = true; Label9.Text = "Postal Code Must be filled !!!!!"; } else { string st_status = "Active"; string st = "User"; con.open_connection(); string str = "insert into registration values('" + txtID.Text + "','" + txtEmail.Text + "','" + txtFname.Text + "','" + txtLName.Text + "','" + radGen.Text + "','" + txtFather.Text + "','" + txtPass.Text + "','" + TextBox1.Text.Trim() + "','" + txtAdd.Text + "','" + txtCity.Text + "','" + txtState.Text + "','" + txtPostal.Text + "','" + txtCountry.Text + "','" + txtPone.Text + "','" + System.DateTime.Now.ToString() + "','" + st_status + "','"+DropDownList1.SelectedValue+"','"+DropDownList2.SelectedValue+"')"; SqlCommand cmd = new SqlCommand(str, con.con_pass()); cmd.ExecuteNonQuery(); con.close_connection(); con.open_connection(); string str1 = "insert into login values('" + txtEmail.Text + "','" + txtPass.Text + "','"+st+"')"; SqlCommand cmd1 = new SqlCommand(str, con.con_pass()); cmd1.ExecuteNonQuery(); con.close_connection(); Label9.Visible = true; Label9.Text = "!!..Hi.." + txtFname.Text + " " + txtLName.Text + "', Your Account is successfully created..!!"; }

} catch (Exception ex) { Label9.Visible = true; Label9.Text = ex.Message; } }}

Connectionusing System;using System.Data;using System.Configuration;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 class connection{ SqlConnection conn;

string get_connect = System.Configuration.ConfigurationManager.ConnectionStrings["ER"].ConnectionString;

public connection() { conn = new SqlConnection(get_connect); }

public void open_connection() { if (conn.State == ConnectionState.Closed) { conn.Open(); } }

public void close_connection() { if (conn.State == ConnectionState.Open) { conn.Close(); } }

public SqlConnection con_pass() { return conn; }}