Header Ads

Header ADS

Part 1. Login Tutorial(Admin & Staff Login) | Attendance Management System using ASP.Net C#


How to create a Login page using asp.net c# for Attendance Management System Project. In this login page, Admin and Teacher/ staff can login to the project.
Here Admin login is a Static login, but Teacher/Staff login is a Dynamic login..


Source Code Starts Here:--

Login.aspx <form id="form1" runat="server"> <div style=" height: 450px;"> <table style="width: 565px; height: 421px; background-color:#00FFFF; margin:0 auto"> <tr> <td colspan="2" align="center"> &nbsp;<img id="Img1" src="Images/login2.png" alt="" runat="server" style="height: 190px; width: 199px"/></td> </tr> <tr> <td colspan="2" align="center" > <h2>Teacher & Admin Login </h2> </td> </tr> <tr> <td align="center" style="width:50%"> <b>Email Id/User ID:</b> </td> <td> <asp:TextBox ID="TextBox1" runat="server" BackColor="Transparent" Height="29px" Width="166px" Font-Bold="True" placeholder="Enter Email_Id/User ID"></asp:TextBox> <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="TextBox1" ErrorMessage="Enter Email-ID" ForeColor="Red"></asp:RequiredFieldValidator> </td> </tr> <tr> <td align="center" style="width:50%"> <b>Password:</b> </td> <td> <asp:TextBox ID="TextBox2" runat="server" BackColor="Transparent" Height="29px" Width="166px" TextMode="Password" Font-Bold="True" placeholder="Enter Password"></asp:TextBox> <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="TextBox2" ErrorMessage="Enter Password" ForeColor="Red"></asp:RequiredFieldValidator> </td> </tr> <tr> <td colspan="2" align="center" > <asp:Button ID="Button1" runat="server" Text="Login" Font-Bold="True" Height="46px" Width="201px" onclick="Button1_Click" /><hr /> </td> </tr> <tr> <td> <asp:Label ID="Label1" runat="server" ForeColor="Red" Font-Bold="True"></asp:Label> </td> <td align="right"> </td> </tr> </table> </div> </form> Login.aspx.cs string str = ConfigurationManager.ConnectionStrings["connection"].ConnectionString; protected void Button1_Click(object sender, EventArgs e) { SqlConnection con = new SqlConnection(str); SqlDataAdapter sda = new SqlDataAdapter("Select * from Teacher where TUserID='" + TextBox1.Text + "' and TPassword='" + TextBox2.Text + "'", con); DataTable dt = new DataTable(); sda.Fill(dt); if (TextBox1.Text == "Admin" & TextBox2.Text == "123") { Response.Redirect("Admin_Home.aspx"); } else if (dt.Rows.Count == 1) { Session["TeacherID"] = dt.Rows[0][0].ToString(); Session["TeacherName"] = dt.Rows[0][1].ToString(); Session["TUserId"] = TextBox1.Text; Response.Redirect("Teacher_Home.aspx"); } else { Label1.ForeColor = System.Drawing.Color.Red; Label1.Text = "Login Failed..."; } }


Thanks for visting:)


No comments

Please do not enter any spam link in the comment box.

Powered by Blogger.