<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %> <!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"> <h2 style="color: blue; font-style: normal"> Simple login form <br /> in asp.net </h2> <div> <table> <tr> <td> <label> UserName</label> </td> <td> <asp:TextBox ID="TextBox1" runat="server" /> </td> </tr> <tr> <td> <label> Password</label> </td> <td> <asp:TextBox ID="TextBox2" runat="server" TextMode="Password" /> </td> </tr> <tr> <td colspan="2" align="center"> <asp:Button ID="Button1" runat="server" Text="Login" OnClick="Unnamed1_Click" /> </td> </tr> <tr> <td colspan="2" align="center"> <asp:Label ID="label1" Text="Invalid Password" runat="server" Visible="false"></asp:Label> </td> </tr> </table> </div> </form> </body> </html>
using System; 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 _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected void Unnamed1_Click(object sender, EventArgs e) { SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["test"].ToString()); SqlDataAdapter da = new SqlDataAdapter("select * from login",con); DataSet ds = new DataSet(); da.Fill(ds); int c=0; for (int i = 0; i < ds.Tables[0].Rows.Count; i++) { string str1 = ds.Tables[0].Rows[i].ItemArray[0].ToString(); string str2 = ds.Tables[0].Rows[i].ItemArray[1].ToString(); if (TextBox1.Text == str1 && TextBox2.Text == str2) { Response.Redirect("Default2.aspx"); c = 1; } } if (c == 0) { TextBox1.Text = ""; TextBox2.Text = ""; label1.Visible = true; } } }
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %> <!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"> <h2 style=" color:blue; font-style:normal "> SIMPLE LOGIN FORM <br /> in asp.net </h2> <div> Welcome to .NET World </div> </form> </body> </html>
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; public partial class Default2 : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } }
No comments:
Post a Comment