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

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);
         rd = cmd.ExecuteReader();
        if (rd.Read())
        {
            Response.Redirect("homepage.aspx");

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



First - Add New WebForm - Selec tLabels & Textboxes & Button  - textbox Change Id name  











     
       Next - Login Button - Double Click  - Go to Coding Page





                       







Next - Coding Page Add NameSpaces & Database Connection in Public








 Next - Add new WebForm Change Name homepage.aspx  &  Write Welcome To homepage






       

  Login Button - Double Click - Write the Coding Select Query using from Register Table
   
            Reader rd check  username & password  If Correct goto  Homepage Or  Else Part Popup Message Display






                                          
OUTPUT

Next - F5 Click - Run the Program  Correct  Username & Password  Given Go to  homepage.aspx




          
                         
                               Control Go to - homepage.aspx





              
                  
                               Given input is Wrong





                   

                                     
                                    Show the Popup Message









0 comments:

Post a Comment