Hi Guys,
This blog we discuss how to write login page
code using asp.net with c#
<body>
<form id="form1" runat="server">
<div>
</div>
<table class="auto-style1">
<tr>
<td class="auto-style2">UserName</td>
<td>
<asp:TextBox ID="txtusername" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td class="auto-style2">PassWord</td>
<td>
<asp:TextBox ID="txtpassword" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td class="auto-style2"> </td>
<td>
<asp:ImageButton ID="ImageButton1" runat="server" ImageUrl="~/Images/submit.png" OnClick="ImageButton1_Click" />
<asp:Label ID="lblmsg" runat="server" Text="Msg"></asp:Label>
</td>
</tr>
</table>
</form>
</body>
Loginpage.aspx.cs file
using System.Data;
using System.Configuration;
public partial class userlogin : System.Web.UI.Page
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["sai"].ConnectionString);
protected void Page_Load(object sender, EventArgs e)
{
}
protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
{
//
con.Open();
SqlCommand cmd = new SqlCommand("select * from logdata
where UserName=@UserName and PassWord =@PassWord",con);
//int
mycount = Convert.ToInt32(cmd.ExecuteScalar());
SqlDataAdapter sdr = new SqlDataAdapter(cmd);
cmd.Parameters.AddWithValue("@UserName",
txtusername.Text);
cmd.Parameters.AddWithValue("@PassWord",
txtpassword.Text);
DataTable dt = new DataTable();
sdr.Fill(dt);
if(dt.Rows.Count > 0)
{
Response.Redirect("gridedit.aspx");
}
else
{
lblmsg.Text = "Invalid Username and password";
}
//
con.Close();
}
}
No comments:
Post a Comment