Wednesday 8 October 2014

How to Create Simple Login Form Using Asp.Net C#

No comments    
categories: , , , ,
SIMPLE LOGIN 


                      DEMO




  Html Coding 

                                         
  <html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <table>
        <tr><td>
            <asp:Label ID="Label1" runat="server" Text="UserName"></asp:Label>
            </td><td>
                <asp:TextBox ID="txtUsername" runat="server"></asp:TextBox>
            </td></tr>
        <tr><td>
            <asp:Label ID="Label2" runat="server" Text="Password"></asp:Label>
            </td><td>
                <asp:TextBox ID="txtPassword" runat="server"></asp:TextBox>
            </td></tr>
        <tr><td colspan ="2">
            <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Login" />
            </td></tr>
    </table>
    </div>
    </form>
</body>
</html>


C# Coding


 protected void Button1_Click(object sender, EventArgs e)
    {
        dbcon();
        query = "select username,password from register  where
         username='"+txtUsername .Text+"' and password='"+txtPassword .Text+"'";
        cmd = new SqlCommand(query, con);
        adp = new SqlDataAdapter(cmd);
        ds = new DataSet();
        adp.Fill(ds);
        rd = cmd.ExecuteReader();
        if (rd.Read())
        {
            Response.Redirect("homepage.aspx");

        }
        else
        {
            Response.Write("<script>alert('Invalid Username or Password')</script>");
        }
       
    }




   

                             



      
                                             
                                      
                                         
                                                                   




0 comments:

Post a Comment